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.

batch rotate pivots

batch rotate pivots

HeavyMetalFox
Advocate Advocate
1,164 Views
7 Replies
Message 1 of 8

batch rotate pivots

HeavyMetalFox
Advocate
Advocate

Hello,

I have many objects and their childrens in my scene (around a thousand) and I need to rotate their pivot in 90 degrees in one direction so that the Z axis is pointing forward instead of the X axis.


When I select them, enter the pivot mode and rotate them all in 90 degrees, all their pivots are pointing in one direction which is undesired and I think its a defect.

How can I select all the objects and rotate their pivots in a relative way to each object by 90 degrees so that the Z axis of each object is pointing forward instead of the X axis?

 

a2.jpg

Accepted solutions (1)
1,165 Views
7 Replies
Replies (7)
Message 2 of 8

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

This command will do what you want.

 

rotate -r -pcp -pgp -os 0 90 0;

 

 

It does a relative roptation (-r) around the object-space axis (-os) and preserves the overall world-space orientation of the object. (-pcp -pgp)

Note: I adapted this from the MEL code in bakeCustomToolPivot.mel script in the Maya installation which is used to bake the custom axis tool in the tool into the selected object(s). 

Brent McPherson
Principle Engineer
0 Likes
Message 3 of 8

HeavyMetalFox
Advocate
Advocate

Thanks alot  brentmc 🙂
It works like a charm, you saved me a week of work.
One question, sometimes meshes are children of parents, when I select the children and parents and execute the script it works for the parent but for the children the pivot is displaced somewhere outwards (but the rotation is fine). So is there a way to apply the script for both parents and children in one shot?

0 Likes
Message 4 of 8

brentmc
Autodesk
Autodesk

I would need a simple example script/scene to better understand the issue.

When baking orientation compensating transforms will be applied to the children so my guess is that you may have to process the selection list yourself to first bake the children and then parents. (or something like that)

Brent McPherson
Principle Engineer
0 Likes
Message 5 of 8

HeavyMetalFox
Advocate
Advocate

"When baking orientation compensating transforms will be applied to the children so my guess is that you may have to process the selection list yourself to first bake the children and then parents. (or something like that)"
Yes this is what I am doing but its time consuming.
Here is a simple example where if I apply the script to the parent then to the children (or  vice versa), the pivot of the children gets displaced:

https://drive.google.com/file/d/14V4AZTLfYHmTn6LYlpKVtaxRGiXlllTm/view?usp=sharing

0 Likes
Message 6 of 8

brentmc
Autodesk
Autodesk

I'm a little surprised the rotate command was moving the child pivots in this manner but it is easy enough to save and restore them as shown in the script below.

{
    // Get selection
    string $objects[] = `ls -sl -transforms`;
    string $shapes[] = `ls -sl -shapes`;
    if (size($shapes) > 0) {
	    string $transforms[] = `listRelatives -path -parent -type transform`;
	    appendStringArray($objects, $transforms, size($transforms));
    }

    // process each selected object
    string $obj;
    for ($obj in $objects) {
        // save pivot position of children    
        int $count = 0;
        float $pivots[];
        string $children[] = `listRelatives -ni -children -type "transform" $obj`;
        for ($child in $children) {
            float $sclPivot[] = `xform -q -ws -sp $child`;
            float $rotPivot[] = `xform -q -ws -rp $child`;
            $pivots[$count++] = $sclPivot[0];
            $pivots[$count++] = $sclPivot[1];
            $pivots[$count++] = $sclPivot[2];
            $pivots[$count++] = $rotPivot[0];
            $pivots[$count++] = $rotPivot[1];
            $pivots[$count++] = $rotPivot[2];
        }

        // bake orientation
        rotate -r -pcp -pgp -os 0 90 0 $obj;

        // restore child pivot positions
        int $i;
        for ($i = 0; $i < $count; $i += 6) {
            xform -ws -sp $pivots[$i] $pivots[$i+1] $pivots[$i+2] $children[$i/6];
            xform -ws -rp $pivots[$i+3] $pivots[$i+4] $pivots[$i+5] $children[$i/6];
        }
    }
}
Brent McPherson
Principle Engineer
0 Likes
Message 7 of 8

HeavyMetalFox
Advocate
Advocate

Hey man,
Thanks for the script but for some reason its not working.
when I apply it to the children it just rotates their displaced pivots but it doesn't bring the pivot to its original position.

0 Likes
Message 8 of 8

brentmc
Autodesk
Autodesk

Onve the pivots are displaced it is too late.

The script needs to be applied when modifying the parent transform as this is what is displacing the pivots. In other words use this script anytime you want to change the local axis of an object and preserve the original pivots of the children.


Brent McPherson
Principle Engineer
0 Likes