[MEL] Create locator at the exact same position of selected object


#1

Hi there !

I have a scene with an animated object, and my main goal is to create a locator at the same spot of the object ( 1st frame ) and paste the same animation,
No constraint, no bake.

I started by the first step, which is creating the locator at the same spot. For this I used xform and the object pivot as wanted final position:

string $objs[]=`ls -sl`;

spaceLocator -n ($objs[0]+"_loc");

float $t[] = `xform -q -ws -t ($objs[0]+".rotatePivot")`;
float $r[] = `xform -q -ws -ro $objs[0]`;
float $s[] = `xform -q -ws -s $objs[0]`;

string $dest = ($objs[0]+"_loc");

xform -ws -t $t[0] $t[1] $t[2] $dest;
xform -ws -ro $r[0] $r[1] $r[2] $dest;
xform -ws -s $s[0] $s[1] $s[2] $dest;

Ok, that worked great, everything is well in place. Now I can check how to copy-paste the animation curves. For that, I used the simple way to verify:

copyKey -option curve "object1";
pasteKey -option replaceCompletely "locator1";

But this is where everything is messing up, because the curves were identical after copy-paste ( good ), but the locator was offseted. Why ?
After som searching, I figured out that the object have his pivot moved ( not because of the script. It was already like this ).
There are values in Local Rotate Pivot and Local Scale Pivot, where my locator have 0 0 0.

I can’t find a way to make everything in line. Tried to add some -rp params in my xform copy, but it creates an offset.

Do you know what I’m missing here? ( without freeze transforming )

Thank you