MEL: Traverse through hierarchy

mel
Abdulla picture Abdulla · Apr 9, 2012 · Viewed 7.9k times · Source

I'm writing a MEL script that will rename all of the joints in a joint hierarchy to a known format. The idea is that you would select the Hip joint and the script would rename the Hips, and go through every other joint and rename it based on its position in the hierarchy.

How can you traverse through a joint hierarchy in MEL?

Answer

cansadadeserfeliz picture cansadadeserfeliz · Apr 10, 2012

If you assign to $stat_element the name of your top joint in the hierarchy and run the following code, it will add a prefix "myPrefix_" to all children elements of that joint.

string $stat_element = "joint1";
select -r $stat_element;
string $nodes[] = `ls -sl -dag`;
for($node in $nodes){
    rename -ignoreShape $node ("myPrefix_" + $node);
}

Hope this helps