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
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Parsing the object tree recursivly?

    Scheduled Pinned Locked Moved SDK Help
    5 Posts 0 Posters 384 Views
    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 Offline
      Helper
      last edited by

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

      On 21/01/2006 at 05:35, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R9.5 
      Platform:   Windows  ;   Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      For an exporter I would like to parse the object tree.

      What's the most elegant way to do this recursively, especially to ensure that visibility, material etc. are read correctly in the scope.

      Does GetNext() find child objects as well or does it work just in the same level of the hierarchy?

      Thanks

      Kabe

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

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

        On 21/01/2006 at 06:50, xxxxxxxx wrote:

        You need to use GetDown to get the child, GetNext does only work on the same level. Search the forum for Hierarchy or so. There is coffee code by Mikael there somewhere, that is easily adaptable to C++.

        HTH

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

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

          On 21/01/2006 at 08:34, xxxxxxxx wrote:

          My standard C++ recursive hierarchy traversal (example) :

          // Remove Child Selections with Selected Parents - recursive  
          //*---------------------------------------------------------------------------*  
          void Selections::RemoveChildSelections(BaseObject* obj)  
          //*---------------------------------------------------------------------------*  
          {  
               for (obj; obj; obj = obj->GetNext())  
               {  
                    // Children first  
                    if (obj->GetDown())     RemoveChildSelections(obj->GetDown());  
                    // Operate on current object  
               }  
          }  
          

          Note that whether you do children first or last can have an impact depending on what you are doing. For instance, when making objects editable or doing bone rotations, better to do them first. Watch your stack usage!

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

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

            On 22/01/2006 at 03:40, xxxxxxxx wrote:

            Thanks, that was very helpful.

            I would suggest that the clarification about GetNext() should find it's way into the SDK docs 😄

            Kabe

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

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

              On 22/01/2006 at 05:48, xxxxxxxx wrote:

              A couple of other important areas of note, especially if you find any object loop causing you grief:

              * Some operations are best done backwards, so you'll want to start at the bottom/back of the list:

              for (obj; obj; obj = obj->GetPred()) {...}
              

              and

              if (obj->GetDownLast()) Func(obj->GetDownLast());
              

              * Operations where you might be shuffling, removing, or adding objects will cause pointer errors, so store them in such circumstances:

              for (obj; obj; obj = nextObj) { nextObj = obj->GetNext(); ... }
              

              I've become use to looking for these, but they are a b!tch to find if you don't know about them.

              HTH!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post