select more loop

the Max reference says this:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
selectMore -- mapped

Adds the node(s) to the set of selected objects. If you want to build a set of selected objects from scratch in a loop, you can use clearSelection() to clear the selection before entering the loop, and use selectMore() in the loop to add objects to the set of selected objects.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I want to create a script that will select the ENTIRE hierarchy under a single node (not just one level down) But I can't seem to write a loop that works.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jonahhawk's picture

I'm all for better tools via

I'm all for better tools via mxs. That said, Ctrl+ PageDown will select all children. PageUp selects parent, PageDown selects child.

 

 

Anton Berg's picture

just a quick question. what

just a quick question. what version of 3dsmax are you using. the "appendifunique" function was added to the maxscript language in 3dsmax version 2008..
------------

I have edited the function somewhat (it still needs 3dsmax 2008 or higher to function)

----------- start code
------------start function
fn selectAllChildren startNodeArray objArray=
(
for startnode in startNodeArray do
(
try (
appendifunique objArray startNode
)catch()
if startNode.children!= 0 then
(
for item in startNode.children do
(
try(
appendifunique objArray item
selectAllChildren item objArray
)
catch()
)
)
)
)

------------end function
objArray =#() --clear the array
--select all children and store in array
selectAllChildren (selection as array) objArray
select objArray -- select all nodes the array
----------- end code

IMPORTANT you need to pass in the objects as an array for this function to work. Either by using the (selection as array) if you want the current selection or create your own array like:
#($bone01,$bone02,$bone52) or
#($onelonleyobject)

OgmaSoul3D
Anton Berg
anton[at]os3d.se

nycwtorres's picture

OK I tried the second one..

OK I tried the second one.. it looked very promising..
The function worked just fine.. but then this happened. Any idea?

>>>>>>>>>>>>>>>>>>>>>>>>
objArray =#() --create an empty array
selectAllChildren $Sequence_Node_SK objArray
#()
-- Error occurred in selectAllChildren()
-- Frame:
-- objArray: #()
-- appendifunique: undefined
-- startNode: $Sequence_Node_SK
-- Type error: Call needs function or class, got: undefined

Anton Berg's picture

In theese both examples

In theese both examples pretend I have an IK bone structure:
bone01 is the main parent.. the first object in the chain

One way of doing it is:
-----
select $Bone01*...*
-----

the problem with this is building the $bone01*..* dynamically. To do this you need to execute a string that you have put together.

select ( execute ( "$" + item.name + "*...*"))

which converts it to a node name.

another way is to create a little function:
-----start code snippet
-----start function ---
fn selectAllChildren startNode objArray=
(
appendifunique objArray startNode
startNode.children
if startNode.children!= 0 then
(
for item in startNode.children do
(
appendifunique objArray item
selectAllChildren item objArray
)
)
)
---end function
objArray =#() --create an empty array
selectAllChildren $Bone01 objArray
--create an array of
--all children of $bone01
--and when you have them selected just
--run a select on the whole group

select objArray
--------- end code snippet

OgmaSoul3D
Anton Berg
anton[at]os3d.se

nycwtorres's picture

OK I found this

OK I found this elsewhere..

(

/*
collects all children recursively. arguments:

obj -- the object to collect its children
allChildren -- by-reference argument used to store child objects
includeParent -- whether the original parent object should be included
includeHidden -- whether hidden objects should be included

*/
fn collectChildren obj &allChildren includeParent:true includeHidden:true =
(
-- check if object should be collected
if (includeHidden or not obj.isHiddenInVpt) and includeParent and finditem

allChildren obj == 0 then
append allChildren obj

-- collect current object's children
for c in obj.children do collectChildren c &allChildren includeParent:true

includeHidden:includeHidden
)

-- initialize children array
local allChildren = #()

-- collect all children
for obj in selection do collectChildren obj &allChildren

-- select them
select allChildren

)

nycwtorres's picture

HELP.. the above script

HELP.. the above script works... then randomly under the same exact circumstances.. I will get this error

-- Syntax error: at name, expected "then" or "do"
-- In line: allChildren o

any ideas why this happens seemingly at random

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.