View Full Version : Going through an hierarchy
eledh_telamion 12-19-2006, 11:55 AM I have a master-node which has a master-controller asigned, and I need to go through it's children to add slave-controllers and to be added to a nodeTab. I have hierarchized as Sphere01 -> Box01 -> Box02-> ... -> BoxN ( -> symbol means has child. So, Box01 is child of Sphere01 and so on).
The questions is, How many children has Spehre01? 1 or N ? I need to be N, but if it returns that has 1 child, how I go through this hierarchy to get N children?
|
|
...how I go through this hierarchy to get N children?
Recursively, of course ;)
Assuming you are asking about MAXScript and not the SDK, an example would be
(
theHierarchy = #() --init. an array to collect children
fn getChildren theParent = ( --pass a parent as argument
for o in theParent.children do ( --for each child of the current parent
append theHierarchy o --append to the array
getChildren o --then call recursively to get its children
)
)
getChildren $ --select parent, call recursive function
print theHierarchy --print the collected children
theHierarchy.count --this is the total # of children including all sub-branches
)
eledh_telamion
12-19-2006, 01:58 PM
Is a SDK plugin, not an script. Sorry!
HalfVector
12-19-2006, 02:19 PM
There we go!.
int GetNumChildren(INode *node)
{
int numChildren = 0;
for (int i = 0; i < node->NumberOfChildren(); i++, numChildren++)
numChildren += GetNumChildren(node->GetChildNode(i));
return numChildren;
}
This function will return the number of children the given node has.
CGTalk Moderation
12-19-2006, 02:19 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.