Hello @JH23,
thank you @Cairyn for answering this. Here is a brief snippet illustrating the use of the undo logic in Cinema 4D SDK.
Cheers,
Ferdinand
"""Example for pushing modifications onto the undo stack.
As discussed in:
https://plugincafe.maxon.net/topic/13366
References:
[1] https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/
c4d.documents/BaseDocument/index.html#BaseDocument.AddUndo
"""
import c4d
def main():
"""
"""
# Create a cube object.
cube = c4d.BaseObject(c4d.Ocube)
# An undo block can contain multiple modifications, e.g., changing the
# position and rotation of an object. Most undo operations have to be
# invoked before the changes have been carried out on an object, e.g.,
# renaming it, changing its position, etc.
#
# The only exception to that is the operation for inserting a new node
# into the scene graph, e.g., inserting a cube object into the document.
# Here AddUndo has to be called after the operation is being carried out.
#
# For details see c4d.documents.BaseDocument.AddUndo()[1].
# Start an undo block.
doc.StartUndo()
# Insert the cube.
doc.InsertObject(cube)
# Add the undo for inserting the cube.
doc.AddUndo(c4d.UNDOTYPE_NEW, cube)
# Close the undo block.
doc.EndUndo()
# Notify Cinema 4D of the changes made by us.
c4d.EventAdd()
if __name__=='__main__':
main()