[Closed] How to select a hierarchy
HI everyone, quick question…
How do I select a node and then select all of his children to then place them in an array?
Thanks all and have a good day.
I’ve been using this snip in one form or another for a while, someone else may have something clearer though.
fn addChildrenToArray theChildren currentObjsToExport =
(
for c in theChildren do
(
append currentObjsToExport c
addChildrenToArray c.children currentObjsToExport
)
)
currentObjsToExport = #(o)
addChildrenToArray o.children currentObjsToExport
You could also make use of the pathName literals in mxs:
fn children obj:selection[1] = (execute ("$'" + (obj.name)+"'/*/.../*"))
select (children())
children() as array
theChildren = children obj:$yourOwnObj as array
-Johan
And another take on it:
fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
select (getTheChildren includeParent:true)
select (getTheChildren())
getTheChildren includeParent:true as array
getTheChildren() as array
-Johan
or alternatively:
fn getChildren obj includeParent:false selectObjs:false =
(
children = for c in obj.children collect c
for c in children do join children (for c in c.children collect c)
if includeParent do append children obj
if selectObjs do select children
children
)
Gravey – note that your function only returns the children and grandchildren; Vsai and JHN’s methods should return the entire hierarchy down from the node specified (so great-grandchildren, great-great-grandchildren, etc. as well).
Guibou – if you need -only- the children: $.children already returns an array with exactly that.
Richard – I’m afraid you are wrong. The function i provided works correctly and in exactly the same way as the getFilesRecursive example function in the maxscript reference under ‘External File Methods’. I’m sure you know it I use this method for collecting recursively fairly often and it works a treat!
I have to admit I don’t use it a lot either, it’s like regex for max But there is some useful stuff you can do it, like writing a single line expression to select an entire hierarchy
-Johan
Johan,
your code is awsome and get all the hierarquy down, but deselect the current first object…
ObjectSet Values
[left]select <PathName>
[/left]
[left]Deselects any current selection first, then selects the node(s) you specified.
[/left]
so,
using selectMore instead select will keep the main selection :
[b][b]selectMore[/b][/b] <PathName>
[left]Adds the specified node(s) to the current selection.
[/left]
fn getTheChildren obj:selection[1] includeParent:false = (execute ("$'" + (obj.name)+"'/"+(if includeParent then "" else "*/")+".../*"))
selectMore (getTheChildren includeParent:true)
selectMore (getTheChildren())
getTheChildren includeParent:true as array
getTheChildren() as array
what about the standard DOUBLECLICK operation ??
eg. double click root select entire hierarchy ? is there any way to play around that ?
unfortnatly at this point,
i can only think about using [i]keyboard.controlPressed[/i]...
If all you’re looking to do is select them, not to use them in a script/array you can use the built in ‘Select Children’ hotkey… i think it defaults to Control+PageDown, if not, just search Customize UI for it.