View Full Version : getting positional info from a locator

 amreet05 May 2006, 02:25 PMquite simple really, just need to figure out how to get the current position of a locator in a scene at any given time, x-y-z format. also how would u go about attaching a joint to a locator somewhere in world space?? i guess its a matter of finding out its location then storing that somewhere, then tell maya to create a joint in the same place. correct?? cheers slider17
mhovland
05 May 2006, 03:52 PM
You need to use either the xform command, or the pointPosition command.

azshall
05 May 2006, 02:26 PM
um.. what about going something like this..

float \$translate[] = `getAttr locator1.translate`;

print ("locator1.tx: " + \$translate[0] + "\n");
print ("locator1.ty: " + \$translate[1] + "\n");
print ("locator1.tz: " + \$translate[2] + "\n");

or..

float \$tx = `getAttr locator1.translateX`;
float \$ty = `getAttr locator1.translateY`;
float \$tz = `getAttr locator1.translateZ`;

print ("locator1.tx: " + \$tx + "\n");
print ("locator1.ty: " + \$ty + "\n");
print ("locator1.tz: " + \$tz + "\n");

Robert Bateman
05 May 2006, 03:51 PM
getting the translate attribute will only return local space translation values. Use xform if you want world space values. In addition though, you may also want to take the "localPosition" atribute into account (since it offsets the locators position from it's parent transform). That would just be a case of multiplying the localPosition value by the transforms world space matrix...

amreet
05 May 2006, 10:27 AM
thanks for the reply guys, just what i was looking for.
i have another question though, after obtaining the positional co-ordinates of a given locator, how can i apply this info to a newly created joint.

what i mean is i want to create a joint in a scene in exactly the spot where a locator is currently sitting. cant seem to do it with any of the joint -""" flags.

any help would be appreciated.

thanks
slider17

Robert Bateman
05 May 2006, 01:18 PM
joint -position \$x \$y \$z;

amreet
05 May 2006, 01:33 PM

i seem to be on the right path, except when i use the example u gave, it creates a joint at 0,0,0. but its, for some reason, parented to the locator im trying to work with.

im using the following code;

float \$x = `getAttr toe_loc.translateX`;
float \$y = `getAttr toe_loc.translateY`;
float \$z = `getAttr toe_loc.translateZ`;

joint -position \$x \$y \$z;

.....the code for the locator is as follows;

spaceLocator -p 1.806 -16.753 3.369;
rename "locator1" "toe_loc";

any help would be appreciated.

cheers
slider17

Stucky
05 May 2006, 01:38 PM
Hi dude. That is because the value it gets from the locator is 0. you have to change the attribute you query. It has to be:

float \$x = `getAttr toe_loc.lpx`;
float \$y = `getAttr toe_loc.lpy`;
float \$z = `getAttr toe_loc.lpz`;

-S

amreet
05 May 2006, 01:45 PM
ok that sorts out the joints showing up where they should be, but they are still parented to their locators. i need to create a joint chain, but i cant do that atm.

is the answer to manually parent each joint to the previous joint???

thanks again for everyone's input, greatly appeciated.

slider17

edit: just realised if i move the locator then run the 'assign translate co-ordinates to variables' script, it makes the joint in the original location of the locator. not good.

amreet
05 May 2006, 02:00 PM
scrap that part about the parenting and joint chain.....i've figured that part out.

but its still not updating itself, regarding the movement of the locators.

eg:

if i create a loactor at 1, 10, 3 --- then i move it to 2, 4, 5 --- then i run my script to create a joint at this new loaction it instead creates it at 1, 10, 3 .
why is this?? i'm guessing its bc im using lpx,y,z. which is local position. i need to use world position right???

slider17

Robert Bateman
05 May 2006, 03:54 PM
i'm guessing its bc im using lpx,y,z. which is local position. i need to use world position right???

getting the translate attribute will only return local space translation values. Use xform if you want world space values. In addition though, you may also want to take the "localPosition" atribute into account (since it offsets the locators position from it's parent transform). That would just be a case of multiplying the localPosition value by the transforms world space matrix...

For clarity i will explain again. A locator is a geometry object with one vertex. It's vertex is "localPosition". using xform, or by getting the translation of it's transform, you will get transform information only. If you query the localPosition, you will get a vertex position in local space only! To get the true world space location of the locator you MUST GET THE WORLD SPACE MATRIX FOR THE LOCATOR, AND THEN MULTIPLY THE LOCALPOSITION ATTRIBUTE BY THAT MATRIX. There is no other way of doing this, period.

Robert Bateman
05 May 2006, 04:07 PM
proc float[] multMatrix(float \$matrix[],float \$pos[])
{
float \$v[];
\$v[0] = \$matrix[0] * \$pos[0] + \$matrix[4] * \$pos[1] + \$matrix[ 8] * \$pos[2] + \$matrix[12];
\$v[1] = \$matrix[1] * \$pos[0] + \$matrix[5] * \$pos[1] + \$matrix[ 9] * \$pos[2] + \$matrix[13];
\$v[2] = \$matrix[2] * \$pos[0] + \$matrix[6] * \$pos[1] + \$matrix[10] * \$pos[2] + \$matrix[14];
return \$v;
}
proc float[] getLocatorPositionProperly(string \$locator_name)
{
string \$relatives[] = `listRelatives -p -f \$locator_name`;
float \$ws_matrix[] = `xform -q -ws -m \$relatives[0]`;
float \$local_position[] = `getAttr (\$locator_name+".lp")`;
return multMatrix( \$ws_matrix, \$local_position );
}

// to use....
\$position = `getLocatorPositionProperly "locatorShape1"`;
joint -p \$position[0] \$position[1] \$position[2];

CGTalk Moderation
05 May 2006, 04:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1