Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from maya import cmds, OpenMaya
- # Logic
- def get_dag_path(objs=None):
- '''
- Grabs the DagPath of multiple objects.
- '''
- dag_paths = []
- # This will handle passing a single name into the function.
- if isinstance(objs, str):
- objs = [objs]
- sel = OpenMaya.MSelectionList()
- if not objs:
- # If nothing was passed in, just go ahead and grab the active selection
- OpenMaya.MGlobal.getActiveSelectionList(sel)
- else:
- # Otherwise loop over the items passed in (assuming they're good)
- # and add them to the selection list.
- for obj in objs:
- sel.add(obj)
- # Proper way to iter a selection list.
- sel_iter = OpenMaya.MItSelectionList(sel)
- while not sel_iter.isDone():
- tmp_dag = OpenMaya.MDagPath()
- # This is great for component selection, but we're doing whole objects
- tmp_obj = OpenMaya.MObject()
- sel_iter.getDagPath(tmp_dag, tmp_obj)
- dag_paths.append(tmp_dag.fullPathName())
- # Don't forget this or you'll loop forever.
- sel_iter.next()
- # This is a cheap way to remove duplicates.
- dag_paths = list(set(dag_paths))
- if not len(dag_paths):
- print 'No objects selected or passed in!'
- else:
- print 'Selected Paths'
- for path in dag_paths:
- print '\t{0}'.format(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement