How To > Sort TrackView Alphabetically |
In general, 3ds Max shows the scene hierarchy in TrackView in the order of object creation. While there are some keyboard shortcuts for moving single objects up and down, there is no built-in function to reorder the TrackView.
Using the fact that unlinking a parented object moves it to the end of the hierarchy, we can write a short script to sort the TrackView display anyway we want.
The following script will sort the objects in TrackView in alphabetical order.
The macroScript will be called AlphaSortTracks . To use the script, you can go to Customize... and drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or assign to a keyboard shortcut.
Using a for loop, we will collect the names of all objects found in the scene in an array called names_array .
The sort method will sort all names in the array in alphabetical order. Now that we have the names in the right order, we will have to retrieve the objects using the names and put them in the same order.
To simulate linking and unlinking and thus reorder the nodes, we will create a temporary dummy object to be used as parent.
The for loop will assign the index of each name from the array to the value of variable i. The by 1 option does not do anything in this case, but if we would change it to –1 , and switch places of the start and end value, we would invert the sorting from ascending (A-Z) to descending (Z-A) order!
Using the getNodeByName function, we convert the object names to nodePath values. This way we get the objects in the right order. The variable i is used as an index to get the i-th element of the array of names.
We are going to sort only objects that are "children of the world", in other words the top-level nodes that are not linked to parents. That’s why we have to check whether the object has a parent. Of there is none (the parent property returns undefined ), we can proceed.
By assigning the dummy object to the . parent property, we link the node to the temporary dummy we created after sorting the names. By assigning undefined to the same property we unlink it again and send it to the end of the scene node database.
Now that the loop has finished its work, we can delete the temporary dummy.
Evaluate the script. To use the script, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut. Create some objects and open TrackView to take a look at their current order. Execute the macroScript and compare the order in TrackView – the nodes should be listed in Alphabetical order now.
As already mentioned in the Step-By-Step description, simply changing the for loop to
will give you sorting in reverse order. You will probably want to give your second version of the script a new name like
or you could even add a prompt asking the user about the desired order mode in the same script.
Another idea for improvements would be to change the script to sort the objects based on some additional property, for example by class (Geometry, Lights, Helpers etc. in blocks by class, then sorted alphabetically within the class blocks)...