Monday, January 3, 2022

Reorder in mel

We have a system in our game where objects appear by their order in the FBX. Changing the order in Maya for a few items is doable, but when more than 10 items are involved it starts to get a bit tedious.


  
So what I initially did was store the selection in an array and store the place of the object in the hierarchy. Then create a temporary group, parent the selection in there and return them to their original position like so:
    string $sel[] = `ls -sl`;
    string $orgParent[] = `pickWalk -direction "up"`;
    string $tmpGroup = `group -empty -name "tmpGroup"`;

    for ($obj in $sel){
        parent $obj $tmpGroup;
        parent $obj $orgParent[0];
    }

    delete $tmpGroup;


Which works, but can get funky when duplicate names are present. Then I found out Maya has a reorder command 😂 Simply select your objects in the order you want them and voilà!
So this

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

    for ($obj in $sel){
        reorder -back $obj;
    }


does exactly the same!

No comments:

Post a Comment