I'm trying to create a script for my scene that splits pre-defined objects into separate parts and exports to STL. It would be easiest to implement by first creating an undo savepoint (the current state of the file), apply all modifiers for pre-defined objects, separate into individual smaller objects after the modifiers have created disjoint parts and export each object into a separate STL file. After all this I would like to restore the scene back to the savepoint meaning I could easily undo everything that the script did to accomplish the final export files.
How to create undo savepoint and later undo all changes done after that in scripting? I already know how to do everything else but I currently have to manually undo or revert after running my script because I don't know how to cleanup after modifying the scene for temporary purposes.
bpy.ops.wm.save_as_mainfile(your_filepath, copy=True)
(IMHO) Also I'd suggest run your python commands using the command line (headless). $\endgroup$