I hope that's not really your code because it will hang. In the last line, you retrieve next_obj always from obj.GetNext() so you get the same object forever. Also, you're skipping the first object before you Do Stuff. And next_obj is not needed anyway:
doc = c4d.documents.GetActiveDocument()
obj = doc.GetFirstObject()
while obj:
# Do stuff
obj = obj.GetNext()
Also, doc is a predefined variable that is already set to the current document.
And you are not traversing into the child objects, but I guess you know that.
As per your question, you can use GeListNode.GetChildren()
to retrieve a list of child objects which you can address by index, but there is no GetSiblings()
built in to achieve the same on the top level. Nevertheless, you can create your own function easily which assembles all siblings into a Python list, or alternatively a function that yields the next sibling, depending on how you want to use it.
The following script shows all siblings on top level (still not traversing the children) by assembling them into a list:
import c4d
from c4d import gui
def GetSiblings(obj):
while obj.GetPred():
obj = obj.GetPred() # go to first sibling
retlist = []
while obj:
retlist.append(obj)
obj = obj.GetNext()
return retlist
def main():
obj = doc.GetFirstObject()
print GetSiblings(obj)
if __name__=='__main__':
main()
Learn more about Python for C4D scripting:
https://www.patreon.com/cairyn