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

    How to use GetChildren() in c++?

    Cinema 4D SDK
    c++
    2
    3
    625
    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.
    • L
      LingZA
      last edited by

      In python, I can op.GetChildren() easily.
      But in c++, GetChildren() is under the
      MAXON_METHOD.
      Because I'm the new to c++, I can not understand the such complex grammar and the usage of this function in c++.
      getchildren.png .
      Please tell me how to get children of an object by using this function in c++.

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @LingZA
        last edited by ferdinand

        Hey @LingZA,

        GelistNode.GetChildren is a convenience function of the Python API which does not exist in the C++ API. You are looking there at HierarchyObjectInterface::GetChildren which is an entirely different entity and method.

        To learn the basics about (classic API) node iteration in C++, I would recommend our GeListNode Manual. I also provided below a small code snippet explaining GeListNode child-iteration in C++.

        Cheers,
        Ferdinand

        Code:

        // The object over whose children we want to loop.
        BaseObject* const parent;
        
        // Iterate over all children with a for-loop.
        for (BaseObject* child = parent->GetDown(); child; child = child->GetNext())
        {
          ApplicationOutput("Child: @", child->GetName());
        }
        
        // The C++ for-loop syntax can be a bit overwhelming for beginners. We can use also a while loop,
        // which is less elegant (while loops are scary), but it might be more obvious for people coming
        // from Python what is going on here: We loop over all children of a node until child.GetNext() is
        // the nullptr, i.e., more or less what is `None` in Python.
        BaseObject* child = parent->GetDown();
        while (child)
        {
          ApplicationOutput("Child: @", child->GetName());
          child = child->GetNext(); 
        }
        

        MAXON SDK Specialist
        developers.maxon.net

        L 1 Reply Last reply Reply Quote 0
        • L
          LingZA @ferdinand
          last edited by

          @ferdinand
          That is great! Thanks!

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