Wow, it took me long enough to stumble upon this forum! I’ve been Maxscripting for awhile but still consider myself a beginner. There are many concepts I’m not comfortable with or have never tried, and hit the occasional brick wall …
I often find myself needing to align bones over time to baked copies of themselves. Because bones should be aligned in hierarchical order, I generally have to control-click the nodes to be aligned manually. I’d rather select them all in one go and have a script determine the order in which things should be aligned.
I figure what I need is a function that will take a selection array, and output a new array with the selected nodes in hierarchical order.
I’ve gotten as far as finding the most ancestral nodes of the input array, by checking each for an undefined parent, or for a parent that is not included in the array. Those nodes are appended to the in-progress output array.
What I’d like to do next is search down each of their lines and add children to the output array in order. I don’t know how to do it though, and was hoping someone could provide an example or advice. Is this a job for do/while, simply appending children to the output array until .children returns undefined? What happens when children.count is greater than 1? It reeks of complexity and breaks my brain.