Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Last active March 9, 2020 07:06
Show Gist options
  • Save SEVEZ/e482e0ddcb64dfd839d366ad264df79a to your computer and use it in GitHub Desktop.
Save SEVEZ/e482e0ddcb64dfd839d366ad264df79a to your computer and use it in GitHub Desktop.
Get selected components indices using Maya API #Snippet
import maya.OpenMaya as om
# To remove duplicates: ids = list(set(ids))
def get_selected_comp_ids():
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
li = 0
path = om.MDagPath()
comp = om.MObject()
stat = sel.getDagPath(li, path, comp)
compFn = om.MFnSingleIndexedComponent(comp)
ids = om.MIntArray()
compFn.getElements(ids)
return ids
print get_selected_comp_ids()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment