SOLVED Get the Next Object of doc.SearchObject() Method?


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.


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:
            print("{0} Is already present".format(objName))

if __name__=='__main__':



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