View Full Version : move pivot point of multiple objects

05 May 2007, 01:55 AM
i guys a gals,

Here's the deal.
I have about 50 copies of the same object, i made those using animation snapshot, i had the pivot point of the master one in the right position, but after the process the pivot points of the copies ended up ramdomly positioned, so i need them to get back into place.

i though i could sort that out via expressions but i'm stuck now.
I'm no coder by no means but you know, one do what one got to do.

this is what i have so far, "i wrote" this from stuff i picked here and there and what gets written in the script editor when i moved the pivot point.

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

for($s in $sel) {

move -r 0 0.437975 0;



can someone correct what i'm doing wrong?

thanks a bunch
see you soon

05 May 2007, 09:22 AM
This should work:

string $objs[];

$objs = `ls -sl`;

for ($obj in $objs)
move 0 0.437975 0 ($obj + ".scalePivot") ($obj + ".rotatePivot");

If you want to do it nice, query the Pivot of your Root Obj instead of typing it directly into the move command...


05 May 2007, 01:49 PM
thank you very much GiantG.

I just realise (and it's silly that i haven't thought about it before) that obviously the command
move 0 0.437975 0 puts all my pivot points in the exact same world position and i need them to be local.

then i tried to do it the nice way as you suggested so i found out that getAttr returns the pivot position.

i thought i could do the following:
string $objs[];

$objs = `ls -sl`;

for ($obj in $objs)


getAttr transform1_Shape50 ($obj + ".scalePivot") ($obj + ".rotatePivot");


//but i get this error: Cannot evaluate more than one attribute.

can you further explain that out for me please?


05 May 2007, 05:16 PM
What do you mean with "...need them to be local"?.
Do you mean centered?
The Pivot shows itself always in Worldspace. But the Coordinates can be read in local or worldspace.

Maybe explain your Plan more in detail...

05 May 2007, 08:04 AM
you could CenterPivot; all your animated objects and then resetPivot; ( to have the values back at tx ty tz.

05 May 2007, 07:48 AM
Hey GiantG. I'm new to mel scripting and tried to query the root object. I was wondering if this is how you would query the pivot point or is there a better way? And I never used (for) before. I used case, if, or else. I was wondering if you can explain what (for) is best used for and ($obj in $objs)? Is it for seperating the stored selection? Because the bottom script I tried without for($obj in $objs) and it only works for one of the selections when selecting all objects.

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

float $rootObj[];
$rootObj = `xform -q -ws -rp pCube1`;

for ($obj in $objs)
move $rootObj[0] $rootObj[1] $rootObj[2] ($obj + ".scalePivot") ($obj + ".rotatePivot");


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

float $rootObj[];
$rootObj = `xform -q -ws -rp pCube1`;

move $rootObj[0] $rootObj[1] $rootObj[2] ($obj + ".scalePivot") ($obj + ".rotatePivot");

05 May 2007, 07:57 AM
Hey sergioduque I think its not working because you can only get one attribute at a time. I tried your way and got the same thing then seperated into two and I got no errors.

Is there a way to combine both those together GiantG?

getAttr transform1_Shape50 ($obj + ".scalePivot");
getAttr transform1_Shape50 ($obj + ".rotatePivot");

05 May 2007, 07:54 PM
GiantG and guys, sorry i took so many time responding back, i'm with a few projects going on at the same this one had to wait a bit.

mean while there's some new info for me to study.
thank you DgAPc and ewerybody for steping in.

this is what i need to do:
in img02 (see ref please) i moved the pivot to where i need them to be, but i need them to be in that same place in the plane, not in the same world position (this is what i meant when i was talking about world and local position). i'm going to try what DgAPc and Ewerybody said.

again thank you guys and sorry about the late response

05 May 2007, 10:52 PM
arghhh, nothing seems to work.
i could change those manually but i'll be doing alot more of this things and more complex ones too.
does someone have any idea about how can i sort this out?

thank guys

05 May 2007, 02:54 AM
Well I Think I figured it out. I got all pivot points to match up to the root object. From your ref picture I don't know if you want it to rotate with the object to because it doesn't rotate.

I had to figure out the center pivot point of the root and childs object by using xform bounding box. Once I found the center pivot point I did a query to find out were the actual pivot point is from the root object. I then subtracted the center pivot point and with the actual pivot point of the root object to figure out the distance from center to actual pivot point. Once I figured out the distance I subtracted the child objects center pivot point with the distance.

I hope that helps you.

----------------How you use the script-------------
First you need to change the name that says pCube1 to the name of your main object (there should only be 2 that say pCube1). Then select all objects except the main object and enter the script.

//the roots object center pivot point
float $rootObjBBPosArr[] = `xform -q -ws -bb pCube1`;
float $rootObjCPpos[];
$rootObjCPpos[0] = (($rootObjBBPosArr[3]-$rootObjBBPosArr[0])/2)+$rootObjBBPosArr[0];
$rootObjCPpos[1] = (($rootObjBBPosArr[4]-$rootObjBBPosArr[1])/2)+$rootObjBBPosArr[1];
$rootObjCPpos[2] = (($rootObjBBPosArr[5]-$rootObjBBPosArr[2])/2)+$rootObjBBPosArr[2];

//the roots object pivot point
float $rootObjWSpos[] = `xform -q -ws -rp pCube1`;

//subtracting the roots object center pivot point with the roots object pivot point
float $pPoint[];
$pPoint[0] = ($rootObjCPpos[0]-$rootObjWSpos[0]);
$pPoint[1] = ($rootObjCPpos[1]-$rootObjWSpos[1]);
$pPoint[2] = ($rootObjCPpos[2]-$rootObjWSpos[2]);

//store the selection of child objects
string $objs[];
$objs = `ls -sl`;

for ($obj in $objs)
//the center pivot point of each object
float $objBBPosArr[] = `xform -q -ws -bb $obj`;
float $objCPpos[];
$objCPpos[0] = (($objBBPosArr[3]-$objBBPosArr[0])/2)+$objBBPosArr[0];
$objCPpos[1] = (($objBBPosArr[4]-$objBBPosArr[1])/2)+$objBBPosArr[1];
$objCPpos[2] = (($objBBPosArr[5]-$objBBPosArr[2])/2)+$objBBPosArr[2];

//subtracting the child center pivot point with the root object
float $pivotPoint[];
$pivotPoint[0] = ($objCPpos[0]-$pPoint[0]);
$pivotPoint[1] = ($objCPpos[1]-$pPoint[1]);
$pivotPoint[2] = ($objCPpos[2]-$pPoint[2]);

//move the childs pivot point
move $pivotPoint[0] $pivotPoint[1] $pivotPoint[2] ($obj + ".scalePivot") ($obj + ".rotatePivot");

Sick Spider
05 May 2007, 03:59 PM
By The pic, I can see its just planes, right ?
If so, why not just use :

string $alPlanes[] = `ls -type "transform" "nameOfPlanes*"`;
for ($everyPlane in $alPlanes)
float $pointZeroPoz[] = `xform -q -ws -t ($everyPlane+".vtx[0]")` ;
move $pointZeroPoz[0] $pointZeroPoz[1] $pointZeroPoz[2] ($everyPlane + ".scalePivot") ($everyPlane + ".rotatePivot");

Of course you can put the pivot on any point that you want, in this case i put it on the -0- point of the mesh.

Have you tried this:

float $scaPoz[] = `getAttr RootPlane.scalePivot`;
float $rotPoz[] = `getAttr RootPlane.rotatePivot`;
string $alPlanes[] = `ls -type "transform" "NameOfPlanes*"`;
for ($everyPlane in $alPlanes)
setAttr ($everyPlane+".scalePivot") $scaPoz[0] $scaPoz[1] $scaPoz[2];
setAttr ($everyPlane+".rotatePivot") $rotPoz[0] $rotPoz[1] $rotPoz[2];

OR, how about this, moves ALL pivots to RootObj:

string $newLoc[] = `spaceLocator`;
delete `pointConstraint -w 1 RootPlane $newLoc[0]`;
float $whatEver[] = `xform -q -ws -t $newLoc[0]`;

string $alPlanes[] = `ls -type "transform" "NameOfPlanes*"`;
for ($everyPlane in $alPlanes)
move $whatEver[0] $whatEver[1] $whatEver[2] ($everyPlane + ".scalePivot") ($everyPlane + ".rotatePivot");
delete $newLoc[0];

Now you can move them and do whatEver....
Hope that helps.

05 May 2007, 12:14 AM
wow thanks a lot to both of you guys, for taking the time to write this down for me.
i feel like you guys just saved my life really! thanks

I'm tring to learn how to code but i don't have any programming background what so ever and it's so hard!!

again thanks a lot guys, i'm off to maya to try those out!

08 August 2007, 11:21 AM
Works great, just my local rotation and scale axes are still aligned to the "base object" of the snapshot (see atrached pic).
The rotation axis can be set, but how would i change the scale axes?

08 August 2007, 07:11 AM
Could use listRelatives to find the parent and quary the location -

string $rootObj[]=`listRelatives -p`;
vector $pivot=`getAttr ($rootObj[0]+".scalePivot")`;

string $objs[]=`ls -sl`;
string $cur;
for ($cur in $objs){
move -r ($pivot.x) ($pivot.y) ($pivot.z) ($cur+".scalePivot") ($cur+".rotatePivot") ;

I love how there are so many different ways to do the same thing in this program. Gives diversity in scripters.

08 August 2007, 09:18 AM
This doesnt do anything about the local axes or am i missing something?
I know how to set local rotation axes but how about scaling?

CGTalk Moderation
08 August 2007, 09:18 AM
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.