acoolrocket

Create locator at pivot point (code error)

Oct 5th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import maya.cmds as mc
  2.  
  3. def createLocAtObjPivot(worldSpace=True):
  4.  
  5. # get the first object that's selected
  6. try:
  7. currSel = mc.ls(selection=True, long=True)[0]
  8. except IndexError:
  9. raise IndexError('Nothing selected, unsure what to run on. Please select something')
  10.  
  11. # pull the pivot you are interested in.
  12. # Maya objects have two pivots, one for rotation, one for scale
  13. # They are not guaranteed to be in the same place
  14. rPiv = mc.xform(currSel, q=True, rp=True, worldSpace=worldSpace) # query rotation pivot
  15. sPiv = mc.xform(currSel, q=True, sp=True, worldSpace=worldSpace) # query scale pivot
  16. print('object:{}: pivots: rPiv:{}, sPiv:{}'.format(currSel,rPiv,sPiv))
  17.  
  18. # create the locator and move it into position
  19. loc = mc.spaceLocator()
  20. mc.xform(t=rPiv) # apply the translate of one of the queried pivots
  21.  
  22. # in case you want to manip the locator further
  23. return loc
  24.  
  25. createLocAtObjPivot(worldSpace=True)
  26. # Error: expected an indented block #
Advertisement
Add Comment
Please, Sign In to add comment