Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Last active March 21, 2018 18:09
Show Gist options
  • Select an option

  • Save SEVEZ/d86bf0a4a497794a94df8f125846ca4f to your computer and use it in GitHub Desktop.

Select an option

Save SEVEZ/d86bf0a4a497794a94df8f125846ca4f to your computer and use it in GitHub Desktop.
Iterate throught selected components via OpenMaya #Snippet
import maya.OpenMaya as om
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
dag = om.MDagPath()
component = om.MObject()
sel.getDagPath(0, dag, component)
if not component.isNull():
if component.hasFn(om.MFn.kMeshPolygonComponent):
print "face"
om.MItMeshPolygon(dag, component)
face_itr = om.MItMeshPolygon(dag, component)
while not face_itr.isDone():
print face_itr.index()
face_itr.next()
elif component.hasFn(om.MFn.kMeshEdgeComponent ):
print "edge"
om.MItMeshEdge(dag, component)
edge_itr = om.MItMeshEdge(dag, component)
while not edge_itr.isDone():
print edge_itr.index()
edge_itr.next()
elif component.hasFn(om.MFn.kMeshVertComponent ):
print "vert"
om.MItMeshVertex(dag, component)
vert_itr = om.MItMeshVertex(dag, component)
while not vert_itr.isDone():
print vert_itr.index()
vert_itr.next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment