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

    Get Objects from the Layer?

    Cinema 4D SDK
    r21 python
    3
    4
    532
    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.
    • B
      bentraje
      last edited by

      Hi,

      Is it possible to retrieve the objects from the layer? Basically, I"m asking a reverse of GetLayerObject.
      I tried GetChildren but it returns None.

      Both this thread and this thread suggest that its not possible.

      Can somebody confirm if this still holds true in the current documentation?

      P.S. No need to create a code for the problem, if its the reverse way
      (i.e. get objects then get layer rather than get layer then get objects). I should be able to create a working code based on the threads above.

      I'm just confirming it if there is a direct way of doing things.

      Thank you.

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi @bentraje, thanks for reaching out us.

        With regard to your request, I confirm there's no "reverse" method allowing you to get all the BaseList2D items being referred by a layer.

        Cheers, R

        1 Reply Last reply Reply Quote 1
        • B
          bentraje
          last edited by

          Thanks for the confirmation.
          Here is the working code I used

          # You can get the layer attached with the object with the obj.GetLayerObject()
          # But there is no direct way to do the reverse (i.e. get objects attached in the layer)
          # Here is a script that does that. 
          # Recursive function was retrieved from [URL-REMOVED]
          
          
          import c4d
          
          def recurse_hierarchy(op):
              count = 0
              obj_dict = {}
              while op:
                  obj_dict[op.GetName()] = op.GetLayerObject(doc).GetName()
                  op = op.GetNext()
              return obj_dict
          
          if __name__=='__main__':
              obj_dict = recurse_hierarchy(doc.GetFirstObject())
              print obj_dict
          

          No further action required


          [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

            Hi,

            if I am not overlooking something here, the function recurse_hierarchy is neither recursive nor will it retrieve the layers for all objects in the scene. It will retrieve the layers for all siblings of the passed node, that were born after that node.

            You probably made a mistake copying your code or misunderstood what is meant by recursive.

            Cheers,
            zipit

            MAXON SDK Specialist
            developers.maxon.net

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