Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Hirarchy search

    SDK Help
    0
    11
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 20/12/2002 at 19:18, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   8.014 
      Platform:    Mac  ;  
      Language(s) :   C.O.F.F.E.E  ;

      ---------
      How can I create a recursive routive that goes through ALL objects in a document?
      I want to go through ALL... even all children.
      Thank you very much in advance.

      Rui Batista

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 21/12/2002 at 00:45, xxxxxxxx wrote:

        Do you remember SpeeDisplay? and the tag issue? 🐵 this code below?

            
            
            
            
            GetActiveTagR(op)  
            {  
             while (op)  
             {  
              var atag=GetActiveTag(op);  
              if (atag)  
               return (atag);
            
            
            
            
              atag=GetActiveTagR(op->GetDown());  
              if (atag)  
               return atag;
            
            
            
            
              op=op->GetNext();  
             }
            
            
            
            
             return NULL;  
            }
            
            
            
            
            GetActiveTagA(doc)  
            {  
             return GetActiveTagR(doc->GetFirstObject());  
            }
            
            
            
            
            main(doc,op)  
            {  
             var atag=GetActiveTagA(doc);  
             if (atag)  
             {  
              var ob=atag->GetObject();  
              println("Active Tag on Object "+ob->GetName());  
             }  
            }
            
            
            
        

        That is also how to do this one 😉
        The GetActiveTagR function recursively looks for an active tag, you can change it to find anything you like, or do anything you want 🐵

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 21/12/2002 at 01:39, xxxxxxxx wrote:

          Also note that recursion cannot handle arbitrarily deep object hierarchies, so if you get stack problems you can search for GetNextHierarchyObject() in the forum archives for a non-recursive function.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 21/12/2002 at 04:03, xxxxxxxx wrote:

            Is that a COFFEE only problem? never had any stack issues with C++, how deep are they likely to be! or is that just "in theory"?

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 21/12/2002 at 05:36, xxxxxxxx wrote:

              What do you mean by "arbitrarily deep object hierarchies", Mikael?
              Oh, and thank you for the listing again 😉 I didn't knew that handling objects could be done in the same way 🙂

              Rui Batista

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 21/12/2002 at 05:40, xxxxxxxx wrote:

                Oh, and about GetNextHierarchyObject()... where are the forum archives?

                Rui Batista

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 21/12/2002 at 06:00, xxxxxxxx wrote:

                  If lets say some bizarre person create nest of maybe a million objects, say, like:
                  Obj 1
                     - Obj 2
                        - Obj 3
                           - Obj 4
                              ...
                                 - Obj 1 million
                  then using a recursive function will run into problems with the stack (run out of the allocated memory for it basically).
                  Can't say I've ever thought about how deep it is safe to go, is there a known limit on the depth of children?

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 21/12/2002 at 07:19, xxxxxxxx wrote:

                    This was more of a problem in early C.O.F.F.E.E., and especially with the naive doubly recursive traversal (i.e. along siblings as well). I believe the limit was about 80 levels there, which was then doubled in R6 if I remember correctly. So you singly recursive function is probably safe for most things.
                    Oh, and for the archive impaired, here's GetNextHierarchyObject() :

                        
                        
                        GetNextHierarchyObject(obj, stopAt)  
                        {  
                          if (!obj) return NULL;  
                          
                          var next;  
                          if (next = obj->GetDown()) return next;  
                          if (next = obj->GetNext()) return next;  
                          
                          var up = obj;  
                          while (up = up->GetUp())  
                          {  
                            if (up == stopAt) return NULL;  
                            if (next = up->GetNext()) return next;  
                          }    
                        }  
                          
                        // Do DoFunction(obj) for all obj that are  
                        // children or grand-children of parent.  
                          
                        var parent = doc->FindObject(...);  
                        var obj = parent->GetDown();  
                          
                        while(obj)  
                        {  
                          DoFunction(obj);  
                          obj = GetNextHierarchyObject(obj, parent);  
                        }
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 21/12/2002 at 07:28, xxxxxxxx wrote:

                      Thank you for the info, Mikael.
                      I think I will stick with the recursive version (it is working now 🙂 It is more elegant and I believe that for the purpose it serves will do just fine.
                      Now, on to the next chalanges of my next plug-in 😉

                      Rui Batista

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 09/03/2005 at 11:13, xxxxxxxx wrote:

                        Quote: Originally posted by David O Reilly on 21 December 2002
                        >
                        > * * *
                        >
                        > Do you remember SpeeDisplay? and the tag issue? 🐵 this code below?
                        >
                        >

                        \> 
                        \> GetActiveTagR(op)  
                        \>  {  
                        \>  while (op)  
                        \>  {  
                        \>  var atag=GetActiveTag(op);  
                        \>  if (atag)  
                        \>     return (atag);
                        \> 
                        \> atag=GetActiveTagR(op->GetDown());  
                        \>  if (atag)  
                        \>     return atag;
                        \> 
                        \> op=op->GetNext();  
                        \>  }
                        \> 
                        \> return NULL;  
                        \>  }
                        \> 
                        \> GetActiveTagA(doc)  
                        \>  {  
                        \>  return GetActiveTagR(doc->GetFirstObject());  
                        \>  }
                        \> 
                        \> main(doc,op)  
                        \>  {  
                        \>  var atag=GetActiveTagA(doc);  
                        \>  if (atag)  
                        \>  {  
                        \>  var ob=atag->GetObject();  
                        \>  println("Active Tag on Object "+ob->GetName());  
                        \>  }  
                        \>  }
                        \> 
                        \> 
                        

                        >
                        > That is also how to do this one 😉
                        >
                        > The GetActiveTagR function recursively looks for an active tag, you can change it to find anything you like, or do anything you want 🐵
                        >
                        >
                        >
                        >
                        > * * *

                        Weird, but where is the GetActiveTag function being called in line 5 from the GetActiveTagR function???

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 10/03/2005 at 06:26, xxxxxxxx wrote:

                          In "resource/modules/coffee/convenience.cof":

                              
                              
                              GetActiveTag(op)  
                              {  
                               var tag = op->GetFirstTag(); if (!tag) return NULL;
                              
                              
                              
                              
                               if (tag->GetBit(2)) return tag; // first element is already the active one
                              
                              
                              
                              
                               return tag->SearchNext(2);  
                              }
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post