Xform does not work right?

isn't xform supposed to return the world position of an object? If I create a sphere and move it to 0,0,5 then freeze transformations and then query the location in world space I get 0,0,0. What is the deal with that?

Your pivot got moved to 0 0 0? in wich case thats the world space position...
just guessing here tough!

What flags did you use with xform?
When I query an objects posistion I always make sure to use the -absolute flag (xform -q -a -ws -t $obj;)

--g

its just dependant on how you use the xform command. Even if your object has been frozen and so thinks its at the origin, you can still get its world space coords .....

/*move an object, freeze its transforms, select it and execute the foolowing*/
{
$sel = ls -sl;
float $location[] = xform("-q", "-ws", "-sp", $sel);
print ($location);
}

Even using:
xform -q -a -ws -t $obj;
causes a return of:
0 0 0
in translation.
Not sure why this is happening

I'm thinking you need to query the worldspace pivot, not the worldspace transformation.

Try xform -q -a -ws -rp $obj;

1 Like

The problem I was having after that is how do you then set an objects translation using that information. If you were to use that like this...
$pos=xform -q -a -ws -rp $obj;
xform -a -ws -rp $pos[0] $pos[1] $pos[2] $obj;
The pivot would be set but not the object also...I think.

1 Like

/*move an object, freeze its transforms, select it and execute the foolowing*/
{
$sel = ls -sl;
float $location[] = xform("-q", "-ws", "-sp", $sel);
print ($location);
//moves object to new position
move $sel $location[0] $location[1] $location[2];
}

Ok not just about things but isnt freezing supposed to zero out the worldspace cordinates?

to get the world space position of an object reliably, you'll want to take the xform of its rotate pivot. so use:

xform -q -ws -rp $obj;

that will reliably give you the absolute world space position of the object.

No that gives the position of your pivot. Your worldspace position is still 0 0 0. So if you do and dig your objects then you see that the cordinates for points is actualy form the center of the world.

But Many people dont care of such things and from their point of view the pivots place in worldspace the cordinate, but this isnt true. Altough from the users point of view it doesent matter! Its still not the same.

But a word of warning on this if you do this when you are faar away from the center of the world your internal precision WILL suffer. Altough most of us are never so far away.

Here's another idea for getting the absolute world space of an obect, use it's .center attribute.
The center attr is the center of an obects bounding box. This may not be ideal on some objects, but it should always comeback as the right value whether the object has been frozen or not.

getAttr ($object+".center");

--g

uumm, i believe from the sounds of his question, thats what he was after. a world space position of an object frozen away from origin. thats about the only definition of the location of an object isn't it? its pivot?

Hey, let's try another way:

string $objectName = "objectNameHere";
pointPosition -w ($objectName + ".rp");

So yes, this is sourcing the rotate pivot of the object. When using the -w (worldspace) flag, it dosen't matter if your object has been frozen or not, it will return the exact worldspace position of the rotate pivot, which is the starting point for all transformations on the object are based on. I use this all the time in my scripts (since it takes less args than xform), never fails.

hey, nice tip warpcat, thanks...

Yes yes but it doesent still change the fact that maya internaly thinks the object is at origin since thats what the transformation matrix says. But yeah the underlying mechanism is such that you could think of the pivot as the actual postion, after all thats what you see.

But the pivots are actualy just offset from this transform location wich is the center of all calc (everything in the geometry is)! And its still not the way it was intended to be used. But yeah provides for a good way of keeping typed values clean.

Also since the pivot postions can and i frwquently do animate them it doesent prowide a wery constant way of knowing this. But the bounding box does, if no deforming takes place.

So this is more of a what to as for question, rather than what is. xform ofcourse answering truthfully.

I'm a little perplexed by your post. It's known that all DAG objects "live" at the origin initially, because that's where shape nodes exist. The whole point of the "transform" node in the DAG hierarchy is to define the shape in worldspace. The transformation matrix dosn't say the object lives at the origin, it defines where the object lives relative to the origin. All I really care about is that the rotatePivot is where the object is currently "at", as defined by the transformation matrix of the shape's host transform. What are you refering to with the bounding box? Possibly, and I honestly mean no offense, but it's often very dificult to read your posts, maybe I'm missing something in the translation? Confused...