move to exact position in worldspace

move to exact position in worldspace

bmagner888
Enthusiast Enthusiast
3,913 Views
4 Replies
Message 1 of 5

move to exact position in worldspace

bmagner888
Enthusiast
Enthusiast

This is infuriating and is driving me f--ing crazy.  My functioned worked perfectly until Maya 2019.  I need an easy, multi-purpose "move to this position" function that will move any object, regardless of hierarchy to an exact worldspace position.


(I have a pre-built function that gets the ws position of whatever i need. That's not the problem.)

 

The core elements of my function are as follows:  
#pm=pymel, gp is my global proc module
lst = pm.ls(sl=True)
p = gp.getPosition(lst[0])
pm.move( p[0], p[1], p[2], lst[1], wd=True, ws=True, a=True)
for aa in lst:
    print(gp.getPosition(aa))


#results:
[-30.182395949167724, 0.2428520000000023, 1.7025716656958796]
[-30.19646394918632, -0.7869360172729467, 3.198302637985919]

The results I get for printing the positions of each object AFTER the move command show different positions even though i used the ' absolute=True'  kwarg:

 

Please help.  I use my snap function in a million other pieces of code and I need it to work properly.  Now every time I turn around it's behaving differently.

Thank you.

Accepted solutions (1)
3,914 Views
4 Replies
Replies (4)
Message 2 of 5

bmagner888
Enthusiast
Enthusiast
Accepted solution

It took a lot of trial and error but I discovered that Maya doesn't move the rotatePivot to the specified location.  It adds an offset from the localSpace pivot information, which is really dumb. 
Is this a new feature since Maya 2019?  It's dumb.  "move/absolute" should just move the thing so it's pivot point is at the location specified. 

So for a proper snap function, you have to unf*ck it by doing an additional relative move by this amount:  
p= pm.getAttr(ths+'.rotatePivot')
pm.move( p[0]*(-1), p[1]*(-1), p[2]*(-1), ths, ls=True, r=True )

0 Likes
Message 3 of 5

jmreinhart
Advisor
Advisor
import maya.cmds as cmds

cmds.xform(ws = True, piv = (0,1,0))
cmds.move(0,1,0,'locator1.rotatePivot', a = True)

both of these methods can be used to move the pivot to a specific worldSpace position

Message 4 of 5

bmagner888
Enthusiast
Enthusiast

That just moves the rotate pivot, not the object.  I need to move the whole object so that the rotate pivot is at the desired worldspace location.  
example:  make a cube.  move it's pivot to somewhere.  use the move command to put it in a specific location.  Maya moves the cube as if the pivot point were the same as before you changed it. This means that the actual worldspace coordinates of the transform node are different than the absolute worldspace coordinates you told it to move to.  This is dumb.
Anyway, the solution is the query the transform's pivot offset and do an additional move by that much (relative =True for the second move command).

0 Likes
Message 5 of 5

jmreinhart
Advisor
Advisor

Ah, sorry I misunderstood what you were trying to do. My bad.