PDA

View Full Version : repeat on all children



RebelHill
04-05-2011, 03:48 PM
So, Im trying to take an action, and apply it to all children of a given item.
Im trying to use a looping statement to do it, but surprise, surprise, its going wrong somewhere, as it only acts on the objects first child item.


{
item = Mesh("MyObject");
ch = item.firstChild();

while (ch)
{
SelectChild();
myAction();
ch = item.nextChild();
}
}

So what have I missed this time?

Thanks.

Castius
04-05-2011, 05:10 PM
You need to recursively call the function.



findChildren: rootObj
{
hierarchyList[++x] = rootObj;
childObj = rootObj.firstChild();

while(childObj)
{
findChildren(childObj);
childObj = rootObj.nextChild();
}
}


This is function in a mirror script i have. http://steelronin.com/plugins/SR_Mirror_v0.1.0.zip

RebelHill
04-05-2011, 06:26 PM
Yes... i found something similar inside clone hierarchy... but I seem to be at a loss as to how to then select each child, and apply my desired command to each.

hmmm...

edit... nope wait... i got it... i think.

Castius
04-05-2011, 07:30 PM
The odd part is knowing that the findChildren function is populating global variables.

Global vars:


hierarchyList;
x = 0;

In "findChildren" this variable is adding(++) to x
And appending the child object to the array.

hierarchyList[++x] = rootObj;

Then you can do what you want with something like this.

for(i = 1; i <= size(hierarchyList);i++)
doStuff(hierarchyList[i]);