I am having an issue with one of my scripts, whereby my API calls to query the UV information are always retrieving data from the Base UV Set and not the Current UV Set. This issue doesn’t happen on every object - some objects work and some do not.
I’m basically setting the current UV Set to the UV set I want to operate on using the standard maya.cmds, but the API calls to get the UV Area are always returning data from the Base UV Set.
Here are some code snippets:
def nameToMDag(name):
selectionList = om.MSelectionList()
try:
selectionList.add(name)
except RuntimeError as e:
print 'RuntimeError: {0}'.format(e)
return None
path = om.MDagPath()
selectionList.getDagPath(0, path)
return path
def getTotalUvArea(mesh):
mdag = rsApi.nameToMDag(mesh)
if not mdag:
return None
pIter = om.MItMeshPolygon(mdag)
areaParam = om.MScriptUtil()
areaPtr = areaParam.asDoublePtr()
totalArea = 0
while not pIter.isDone():
pIter.getUVArea(areaPtr)
area = areaParam.getDouble(areaPtr)
totalArea += area
pIter.next()
return totalArea
# this is a class function, omitted the rest.
def getUVSpaceUtilizationRatio(self):
uvSets = cmds.polyUVSet(self._shape, q=True, auv=True)
if 'BakedLighting' in uvSets:
cmds.polyUVSet(self._shape, uvs='BakedLighting', cuv=True)
area = rsMod.getTotalUvArea(self._shape) # this sometimes returns the area of the Base UV Set, not the Current UV Set.
if not area:
return None
u, v = cmds.polyEvaluate(self._shape, b2=True)
bbArea = (u[1] - u[0]) * (v[1] - v[0])
try:
ratio = area / bbArea
except ZeroDivisionError as e:
ratio = None
self._uvRatio = ratio
return ratio