C4D Crashes on Getting All Specific Type of Objects

  • Hi,

    I'm trying list an object with a specific type using the recursive code from the documentation. But currently, it crashes/freezes the program.

    Here's the code so far:

        def recurse_hierarchy(op):
            obj_list = []
            while op:
                if op.GetType() == c4d.Ospline: # the line where it freezes
                    obj_list+= recurse_hierarchy(op.GetDown())
                    op = op.GetNext()
            return obj_list
        all_spline_objects = recurse_hierarchy(doc.GetFirstObject())

    Is there a way around this?

  • Hi,

    you have to unindent op = op.GetNext() one tab or the while loop condition will always be True unless your whole document consists of spline objects.


  • Hello,

    nothing to add, as @zipit answer (thanks again), be careful to change op or it will be "true" for ever.

    And please, don't forget to use the "Ask as question" mark for the thread and solved ^^


  • @zipit

    Thanks for the response and clarification. Works as expected

    Sorry about that. Will be more careful next time.

Log in to reply