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.

  • 2
    $\begingroup$ Undo is quite limited and there is no reliable mechanism so the easiest way to do this is just saving a temp file using 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$
    – brockmann
    Sep 11, 2021 at 16:01
  • $\begingroup$ I'm trying to create open source lock design where I can distribute .blend file and the end user can simply dial keycut into custom properties of object called KEYCUTS and then run script to export all parts as STL files ready to print. As such, it would be nicer to run script from the UI because the user already has Blender open and active. $\endgroup$ Sep 12, 2021 at 22:23
  • 1
    $\begingroup$ Makes no difference, just save a copy and open/close the temp file @MikkoRantalainen $\endgroup$
    – brockmann
    Sep 13, 2021 at 9:53


You must log in to answer this question.

Browse other questions tagged .