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

    Very Slow - AddUndo() Before Removing Object From the Document

    Cinema 4D SDK
    python 2023
    2
    2
    424
    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.
    • W
      wuzelwazel
      last edited by

      I'm looping through 397 objects in my current scene and removing them all with the following code:

      for obj, _ in instance_grp:
          self.doc.AddUndo(c4d.UNDOTYPE_DELETEOBJ, obj)
          obj.Remove()
      

      I've timed the sub-section of the script where this is happening. When I AddUndo() here the script takes a total of ~4.3 seconds to run and this section in particular takes ~3.1 seconds.

      If I comment out the AddUndo() line like so:

      for obj, mtx in instance_grp:
          #self.doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
          obj.Remove()
      

      Then the total runtime of the script is ~1.2 seconds and this section takes ~0.09 seconds. This is unexpected. Is there something I could be doing differently; is this a bug?

      1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov
        last edited by

        Hello @wuzelwazel,

        Depending on the size and complexity of objects on your scene (namely on the objects that are processed with the script) adding an undo can be quite an expensive operation to execute. There was some recent work done that should affect the undo-stack in a positive way in the following releases.

        Let me know if you have any further questions.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

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