Skip to content

Instantly share code, notes, and snippets.

@Onefabis
Last active August 2, 2016 15:45
Show Gist options
  • Save Onefabis/953e38077f16383db51497712611532b to your computer and use it in GitHub Desktop.
Save Onefabis/953e38077f16383db51497712611532b to your computer and use it in GitHub Desktop.
Prints elements id of selected elements
import maya.api.OpenMaya as om2
#get vertices ID of selected faces
sel = om2.MSelectionList()
sel = om2.MGlobal.getActiveSelectionList()
dp, comp = sel.getComponent(0)
mItVtx = om2.MItMeshPolygon(dp,comp)
idx = []
while not mItVtx.isDone():
point = mItVtx.getVertices()
idx.extend(point)
mItVtx.next(0)
print list( set( idx ) )
##################################################
import maya.api.OpenMaya as om2
#get vertices ID of selected components
sel = om2.MSelectionList()
sel = om2.MGlobal.getActiveSelectionList()
dp, comp = sel.getComponent(0)
compFn = om2.MFnSingleIndexedComponent(comp)
ids = om2.MIntArray()
ids = compFn.getElements()
print ids
import maya.api.OpenMaya as om2
#iterate with specified face IDs
poly_ids = [0, 2, 4, 5]
selL = om2.MSelectionList()
selL.add('pSphere1')
mObj = om2.MObject()
mObj = selL.getDagPath( 0 )
mItVtx = om2.MItMeshPolygon(mObj)
for x in poly_ids:
mItVtx.setIndex(x)
point = mItVtx.getVertices()
print point
mItVtx = om2.MItMeshPolygon(mObj)
mItVtx.setIndex(2)
point = mItVtx.getVertices()
print point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment