Iterating through children
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/03/2011 at 14:18, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : C++ ;---------
Hello,I would like to Iterate through the children of a particular object in the OM. Let's call this object BOB. So I would like to check first to see if BOB has any children.. So I do this with
if(BOB->GetDown()){ //Do Something }
Now inside of that If statement I would like to iterate through all of the children that BOB has to see if any of his children have a particular name..
so in my head it looks like this..
if(BOB->GetDown()){ for(BOB->GetDown() ; BOB->GetLast() ; BOB->GetDown->GetNext()){ GePrint(op->GetName()); } }
So I have an idea of how it should be done but I am a little fuzzy on all the details. Could someone drop me a sample code of how I should do it?
Thanks so much..
~Shawn
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/03/2011 at 14:42, xxxxxxxx wrote:
I think I figured it out... This is what I am doing now.. Please let me know if there is a better way.
if (objectToOrbit->GetDown()){ BaseObject *obj = objectToOrbit->GetDown(); while(obj) { if(obj->GetName() == "Orbit Path"){ GePrint("FOUND THE MONKEY"); } obj = obj->GetNext(); } }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/03/2011 at 15:00, xxxxxxxx wrote:
Hehe, why did you first call "GetLast()" ? ^^
If you use GetNext() after GetLast() there will be none. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/03/2011 at 15:03, xxxxxxxx wrote:
I think the method in the second post will work fine, it's the method I use (for what that's worth!!). The only problem is if your child objects themselves have children and you need to check those. You need a recursive function if that's the case, but for a single level of child objects this looks fine.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/03/2011 at 01:05, xxxxxxxx wrote:
To iterate through the complete hierarchy of a document do something like this.
void WalkTheHierarchy(BaseObject *op) { while(op) { StatusSetSpin(); // do something with op.... GePrint(op->GetName()); WalkTheHierarchy(op->GetDown()); op = op->GetNext(); } } ... WalkTheHierarchy(doc->GetFirstObject());
You could have found this information in the forum btw, please use the forum search.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/03/2011 at 05:25, xxxxxxxx wrote:
While "WalkTheHierarchy(op->GetDown())" is just fine, you can increase performance and avoid pushing onto/popping off a bunch of stack stuff by doing a quick check first:
...
if (op->GetDown()) WalkTheHierarchy(op->GetDown());
...This adds a conditional and a duplicate call but it means that you stay within this iteration of the recursion without needless recursion stacking.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/03/2011 at 09:55, xxxxxxxx wrote:
Thanks Guys!