CV computation as suggested in the linked post is done by the third-party software meshtool.
I guess you could extract a submesh first and then run the gradient computation only on the submesh. Specific questions to meshtool are better placed in their platform, though: https://bitbucket.org/aneic/meshtool/src/master/