Advertisement
Guest User

Some Stuff

a guest
Oct 6th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. from maya import cmds, OpenMaya
  2.  
  3. # Logic
  4. def get_dag_path(objs=None):
  5.     '''
  6.    Grabs the DagPath of multiple objects.
  7.    '''
  8.  
  9.     dag_paths = []
  10.  
  11.     # This will handle passing a single name into the function.
  12.     if isinstance(objs, str):
  13.         objs = [objs]
  14.  
  15.     sel = OpenMaya.MSelectionList()
  16.     if not objs:
  17.         # If nothing was passed in, just go ahead and grab the active selection
  18.         OpenMaya.MGlobal.getActiveSelectionList(sel)
  19.     else:
  20.         # Otherwise loop over the items passed in (assuming they're good)
  21.         # and add them to the selection list.
  22.         for obj in objs:
  23.             sel.add(obj)
  24.  
  25.     # Proper way to iter a selection list.
  26.     sel_iter = OpenMaya.MItSelectionList(sel)
  27.  
  28.     while not sel_iter.isDone():
  29.  
  30.         tmp_dag = OpenMaya.MDagPath()
  31.         # This is great for component selection, but we're doing whole objects
  32.         tmp_obj = OpenMaya.MObject()
  33.  
  34.         sel_iter.getDagPath(tmp_dag, tmp_obj)
  35.  
  36.         dag_paths.append(tmp_dag.fullPathName())
  37.  
  38.         # Don't forget this or you'll loop forever.
  39.         sel_iter.next()
  40.  
  41.     # This is a cheap way to remove duplicates.
  42.     dag_paths = list(set(dag_paths))
  43.  
  44.     if not len(dag_paths):
  45.         print 'No objects selected or passed in!'
  46.     else:
  47.         print 'Selected Paths'
  48.         for path in dag_paths:
  49.             print '\t{0}'.format(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement