Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Created August 30, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SEVEZ/f2b053f14e17cd5bdc6f to your computer and use it in GitHub Desktop.
Save SEVEZ/f2b053f14e17cd5bdc6f to your computer and use it in GitHub Desktop.
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