Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    C4D Crashes on Getting All Specific Type of Objects

    Cinema 4D SDK
    r20 python
    3
    4
    517
    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,

      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.append(op)
                      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?

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by

        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.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 2
        • ManuelM
          Manuel
          last edited by Manuel

          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 ^^

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

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

            @zipit

            Thanks for the response and clarification. Works as expected

            @m_magalhaes
            Sorry about that. Will be more careful next time.

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