Looking for a function which returns a list of all UV shells from a selected object. Most of the stuff I found on the internet is a bit hacky and doesn't end up working well. I read through the official docs and I couldn't find anything like this so it makes me wonder does it even exist. Basically I would need a list of those UV shells and to be able to select faces/verts/edges inside of it.
MEL solution is fine aswel.
Using Maya 2018 by the way.
Replies
import maya.OpenMaya as om import maya.cmds as cmds def getUvShelList(name): selList = om.MSelectionList() selList.add(name) selListIter = om.MItSelectionList(selList, om.MFn.kMesh) pathToShape = om.MDagPath() selListIter.getDagPath(pathToShape) meshNode = pathToShape.fullPathName() uvSets = cmds.polyUVSet(meshNode, query=True, allUVSets =True) allSets = [] for uvset in uvSets: shapeFn = om.MFnMesh(pathToShape) shells = om.MScriptUtil() shells.createFromInt(0) # shellsPtr = shells.asUintPtr() nbUvShells = shells.asUintPtr() uArray = om.MFloatArray() #array for U coords vArray = om.MFloatArray() #array for V coords uvShellIds = om.MIntArray() #The container for the uv shell Ids shapeFn.getUVs(uArray, vArray) shapeFn.getUvShellsIds(uvShellIds, nbUvShells, uvset) # shellCount = shells.getUint(shellsPtr) shells = {} for i, n in enumerate(uvShellIds): if n in shells: shells[n].append([uArray[i],vArray[i]]) else: shells[n] = [[uArray[i],vArray[i]]] allSets.append({uvset: shells}) return allSets[{u'map1': {0: [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]}}]
0: - Representing first shell
[0.0, 0.0] -1st point
[1.0, 0.0] -2nd
[0.0, 1.0] -3rd
[1.0, 1.0] -4th
Now I managed to iterate through this and obtain each UV shell and its respective UVs.
Now the problem is using this data to obtain UV selection again. This needs to be put in a way that cmds.select() can understand.
Cheers man for that