Hierarchy reorder

hey guys im tryin to write a script that dose the following in max need some pointer on where to begin or if this type of script is out there

this so the frist obj is at the top of the hierarchy under the parent

select a parent

look for children an add to an array

detach them

sort by alphabetical order

then reattach starting by the first obj in the list

Not got max in front of me, but try this:

myarray = #()

theparent = $
select theparent.children

$.parent = undefined

myarray = getCurrentSelection()
myarray = sort myarray

for obj in myarray do obj.parent = theparent

Nodes can’t be sorted, but Eric I’m guessing you wanted to sort them by object name? If so, something like this should work, assuming the objects are named uniquely in your scene.

parent = $
if (parent.children.count > 0) then (
 child_names = #()
 for c in parent.children do (
  append child_names c.name
  c.parent = undefined
 )
 sort child_names
 for c_name in child_names do (
  c = getNodeByName c_name
  c.parent = parent
 )
)

If they’re not named uniquely you’ll have to go to more trouble. Like keep another array mapping node handles to names or something.

thanks guys ill give it a go on this an let you know thanks

it works but the order in the schematic view is still the same

ie
top
box03
box02
box01
box04

the scripts prints out the right order but in the schematic view is still like the top we want the order to reflect in the schematic view