Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

World coordinates of the parented object

World coordinates of the parented object

Anonymous
Not applicable
1,895 Views
9 Replies
Message 1 of 10

World coordinates of the parented object

Anonymous
Not applicable

Hello,

I am animating a character who has a mace on a chain parented to his hand. How can I see the world coordinates of the mace?

0 Likes
1,896 Views
9 Replies
Replies (9)
Message 2 of 10

osidedan
Advocate
Advocate

Hello! 

The worldspace position of an object can easily be found with the xform command in Mel. You can run this in the script editor, the Mel command field, or work it into an expression:

xform -q -t -ws nameOfTheMace;

Just replace "nameOfTheMace" with the name of your mace, and it will print out the world position in the script editor.

To elaborate a bit on the -q, -t, and -ws flags, those are telling the xform command to query(q) the translation(t) in world space(ws) of the mace. 

Hope that helps!

 

side note, if you need to put it into a variable that you can use somewhere else in script, you need to use a formatting like this:

float $worldPos [] = `xform -q -t -ws nameOfTheMace`;
print $worldPos;

Notice how there are back ticks around the command. This is necessary to take the return info from the command and put it into a variable. 

 

Let me know if you have any questions on any of that!

 

further reading:

More info on xform:
https://download.autodesk.com/global/docs/maya2012/en_us/Commands/xform.html 

 

and if you're brand new to Mel, here is the root page for Mel info from Autodesk (I'm on 2018, but the info should be the same):
http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-60178D44-9990-45B4-8B43-9429D54DF70E 

 

0 Likes
Message 3 of 10

Parmenides
Collaborator
Collaborator

Hello Osidedan, I have a question about the next step.  I guess the question this comes up is because when you use a constraint to connect to something, move it and then disconnect it, the constrained object reverts back to its original position. But it needs to stay in that exact location to be constrained to the next object. 

 

The first script you provided above indeed shows the world position but how do you apply it in the channel box when it shows the position as zero? (since it is parented).   I can get the before and after positions but not sure how to apply it?

0 Likes
Message 4 of 10

mcw0
Advisor
Advisor

If you want to constrain to multiple objects, just repeat the constraint process with the other objects.  You'll now see weights on your constraint node for each object.  Just animate the weight values to switch from one target to another.  Some planning is involved so that there aren't any pops when switching.  Hope that makes sense.

0 Likes
Message 5 of 10

Parmenides
Collaborator
Collaborator

Thanks. I am familiar with constraints. The question was more about how to apply absolute positions in the channel box or wherever it needs to be done.

0 Likes
Message 6 of 10

mcw0
Advisor
Advisor

Not sure I understand.  If an object is constrained, the translation values are driven by the constraint.  If you want to apply world space values, then you have to uncheck "inherits transforms".  And then if the object is still constrained and you want to input your own values, then you'll be dealing with one of the blend nodes.  For example, blendTwoAttr, or blendWeighted, or blendColors.

0 Likes
Message 7 of 10

Parmenides
Collaborator
Collaborator

When you do multiple constraints, yes you use the blending. But when you turn off all constraints (0), the constrained object jumps to another position which isn't idea.  My question is about finding the absolute or world position before the jump so that I can use those to put the object that jumped back in that exact position/rotation. The xform snippet about gives the locations but how to apply it?

0 Likes
Message 8 of 10

mcw0
Advisor
Advisor

If you use one of the "Waiting..." nodeStates, the object will not "jump" to the rest position.  I'm not in Maya so I don't remember all of the nodeState options.

0 Likes
Message 9 of 10

Parmenides
Collaborator
Collaborator

Can you elaborate further on this? Thanks. 

0 Likes