Very Slow - AddUndo() Before Removing Object From the Document
-
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?
-
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