C4D : GetNext() node travesal - infinite loop

C4D : GetNext() node travesal - infinite loop

nicholas_yue
Participant Participant
668 Views
2 Replies
Message 1 of 3

C4D : GetNext() node travesal - infinite loop

nicholas_yue
Participant
Participant

I am writing some pipeline code that is traversing a C4D scene. The way I found in their documentation when iterating nodes in C4D scenegraph is via the object's GetNext() method.


However, when my code reach the <display driver> node that is created by the AOV editor in C4D for Arnold, the GetNext() method of that node does not point to the next node but point to itself resulting in C4D hanging.


Is this a known problem ? Is there a workaround ?


OUTPUT FROM C4D PYTHON CONSOLE

>>> doc = c4d.documents.GetActiveDocument()
>>> obj = doc.GetFirstObject()
>>> print(obj)
<c4d.BaseObject object called 'Arnold distant_light/Arnold Light' with ID 1030424 at 0x0000027ACD423D10>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423AD0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423FB0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423DF0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423AD0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423FB0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423DF0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423AD0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423FB0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423DF0>
>>> obj.GetNext()
<c4d.BaseObject object called '<display driver>/Arnold Driver' with ID 1030141 at 0x0000027ACD423AD0>
>>>

0 Likes
Accepted solutions (1)
669 Views
2 Replies
Replies (2)
Message 2 of 3

peter.horvath6V6K3
Advisor
Advisor
Accepted solution

Your code is not correct, you call GetNext() on the same object over and over. Check out this code which iterates over the top level objects in the scene:

import c4d
from c4d import gui

# Main function
def main():
    doc = c4d.documents.GetActiveDocument()
    obj = doc.GetFirstObject()
    while obj is not None:
        print(obj)
        obj = obj.GetNext()

# Execute main()
if __name__=='__main__':
    main()
0 Likes
Message 3 of 3

nicholas_yue
Participant
Participant

Got it. Thanks.

0 Likes