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 the Next Object of doc.SearchObject() Method?

    Cinema 4D SDK
    r21 python
    2
    3
    555
    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 there a way to get the "next" object of doc.SearchObject() method.
      As I understand, if there are two objects name cube. The method will retrieve first cube in the outliner.
      Is there a way to get the next cube object?

      My use case is this:

      1. Check if there are objects with the same name
      2. If there are, throw an error. Every object must have a unique name.

      I guess I can do this with the traversing objects hierarchy code provided by the plugincafe.
      Storing each object name and comparing them with each other.

      But it would be nice if I can just do this with doc.SearchObject so I can shorten the logic.

      Regards,
      Ben

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi unfortunately there is nothing built-in so you have to iterate over the scene.

        import c4d
        
        def HierarchyIterator(obj):
            while obj:
                yield obj
                for opChild in HierarchyIterator(obj.GetDown()):
                    yield opChild
                obj = obj.GetNext()
        
        
        def main():
            names = set()
            for obj in HierarchyIterator(doc.GetFirstObject()):
                objName = obj.GetName()
                if objName not in names:
                    names.add(objName)
                else:
                    print("{0} Is already present".format(objName))
        
        
        if __name__=='__main__':
            main()
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

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

          @m_adam

          Ah gotcha. Thanks for the confirmation and the sample code.

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