Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extend polygons selection to shell
import maya.OpenMaya as om
import maya.cmds as cmds
def expandSelection():
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
dag = om.MDagPath()
obj = om.MObject()
# get the active object (dag) and its selected components (obj)
sel.getDagPath(0, dag, obj)
# Here we create an iterator over the selected components
itr = om.MItMeshPolygon(dag, obj)
# Now we add all faces of the selection to the array
currfaces = om.MIntArray()
while not itr.isDone():
currfaces.append(itr.index())
itr.next()
# finally we reconvert the MIntArray to a simple list
currfaces = list(currfaces)
# and use maya.cmds to extend the polygon-selection to their shells
cmds.polySelect(dag.fullPathName(), extendToShell = currfaces, add=True)
expandSelection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.