Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Arranging Objects by order of Object Manager

    Cinema 4D SDK
    python
    4
    10
    1.8k
    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.
    • orestiskonO
      orestiskon
      last edited by

      Hi all,
      I'd like to arrange a list of objects based on the order they have in the Object Manager.
      Is there an efficient way to do that without iterating through all of the objects of the scene?

      I've been searching for something like Hierarchical Distance that I could compare with the scene root, or perhaps an index of the object in the Object Manager list, but haven't found something relevant.

      Perhaps there is there another idea on how to achieve it?

      1 Reply Last reply Reply Quote 0
      • lasselauchL
        lasselauch
        last edited by lasselauch

        My guess is that iterating over with enumerate BaseDocument.GetObjects(self) would be efficient enough..?

        For example:

        all_objs = doc.GetObjects()
        for i, obj in enumerate(all_objs):
            # Distance can be whatever float or integer
            your_dist = i * 27
            pos = c4d.Vector(your_dist, 0, 0) 
            obj.SetAbsPos(pos)
        
        1 Reply Last reply Reply Quote 1
        • orestiskonO
          orestiskon
          last edited by orestiskon

          @lasselauch Thanks Lasse, that's great advice, GetObjects() should work.

          1 Reply Last reply Reply Quote 1
          • orestiskonO
            orestiskon
            last edited by orestiskon

            Having tried it out, a problem is the GetObjects() only gives the top objects of the document without their children.
            I could make a recursive iteration to go through all of the document's objects but that would slow it down significantly...

            1 Reply Last reply Reply Quote 0
            • lasselauchL
              lasselauch
              last edited by lasselauch

              I could make a recursive iteration to go through all of the document's objects but that would slow it down significantly...

              Yeah, but that's basically the way to go... Not sure if the following yields faster results:

              def get_next_element(op):
                  if not op:
                      return
                  if op.GetDown():
                      return op.GetDown()
                  while (not op.GetNext()) and op.GetUp():
                      op = op.GetUp()
                  return op.GetNext()
              
              def main():
                  obj = doc.GetFirstObject()
                      
                  while obj:
                      # act on obj
                      print(obj.GetName())
              
                      obj = get_next_element(obj)
              

              Always wondered what approach would yield faster results...

              Feel free to do some testing, would love to hear your results. 🙂

              1 Reply Last reply Reply Quote 1
              • ManuelM
                Manuel
                last edited by

                Hi,

                I'm not sure to understand what's the goal here. Could you give us more information ? Why you need to be sure the order is the same?

                Cheers,
                Manuel

                MAXON SDK Specialist

                MAXON Registered Developer

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

                  Hello @orestiskon,

                  without further questions or replies, we will consider this topic as solved by Monday, the 30th and flag it accordingly.

                  Thank you for your understanding,
                  Ferdinand

                  MAXON SDK Specialist
                  developers.maxon.net

                  1 Reply Last reply Reply Quote 0
                  • orestiskonO
                    orestiskon @Manuel
                    last edited by orestiskon

                    @m_magalhaes Hi Manuel, sorry I missed your message.

                    I have an Include/Exclude lists of objects, and I would like to iterate on them in a hierarchical order.
                    If I just go with the order of the list, the user might not have added them in the hierarchical order.

                    Doing it in the same order they are displayed in the Object Manager is a reliable way of ordering them hierarchically, so I was looking for an efficient way of doing that.

                    Do you have any other ideas than iterating through all the objects of the project?

                    1 Reply Last reply Reply Quote 0
                    • ManuelM
                      Manuel
                      last edited by Manuel

                      One moment later...

                      hi,

                      sorry for the delay.

                      I would use SetDparameter to organize the in/exclude list whenever this list is changed.

                      Other than that, there's no helper on the API for this task.

                      Cheers,
                      Manuel

                      MAXON SDK Specialist

                      MAXON Registered Developer

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

                        Hello @orestiskon,

                        without any further questions, we will consider this topic as solved by Monday, the 25th and flag it accordingly.

                        Thank you for your understanding,
                        Ferdinand

                        MAXON SDK Specialist
                        developers.maxon.net

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