Recreating group-hierarchy with transformations via Python?

Recreating group-hierarchy with transformations via Python?

Anonymous
Not applicable
680 Views
0 Replies
Message 1 of 1

Recreating group-hierarchy with transformations via Python?

Anonymous
Not applicable

Hi,

Since a couple days I am working on a Python script to recreate a group hierarchy in Maya.

Basically my goal is to copy a group-stack (a bunch of nested groups) with all their transformations, which contain a certain type (e.g. mesh or light).

At the moment, I am going through the scene, search for a mesh-type. Once I found one, see if it is a children of something. If yes, recreate that parent object and make that mesh a child of it, then apply the transformations to that newly created parentobject. Now go further and check if that parent object has another parent object, and so on.
The big problem I have now, are the world space pivots. They make everything a lot harder at the moment, since they take translations, rotations, scaling and local pivots into account, of all parents.
It wouldn't be a problem to calculate the world pivots if there is only translation and local pivots, but including rotation and scaling, changes it a lot. Changing translateX doesn't only change world pivot x anymore. The changes are happening on multiple axis.
Unfortunately I am not able to share my current Python script (due to work permission), but I it would be great if anyone has an idea or easier approach to achieve my goal?

(It is important to keep the old hierarchy, and create a new one)
Maybe there is a function to simply copy/paste the whole stack and swap that certain element? (Please keep in mind, a group can have many mesh-types as well as many other groups within groups within groups)

I have an idea in mind, but it feels very wrong and unnecessary, but maybe I have no other choice. I recreate the whole group-stacks with zero rotation and scaling reset to 1.0. Then recalculate all the pivots for all groups and recreate them. Later on apply rotation and scaling to the individual group-objects.

I've attached a really small example scene. Once I copy the hierarchy via my script, I am not able to retain the correct world pivot on certain groups and therefore the position of the mesh is wrong.

Any help would be great!

Thank you,
Chris

0 Likes
681 Views
0 Replies
Replies (0)