Undo recording in Python

Hi everyone !

I realized that when I run a Python script, I cannot use an Undo command:

To situate, I am trying to do successive boolean differences, and if only one fails, Undo all the operations, move an object and then restart the boolean operations.

It seems to come from the fact that there is no way to record the successive operations.

Do you have any idea to get around this problem ? Is it planned to implement it for Python ?

Thanks a lot,

The script is running in the context of a single command which is the level that undo recording occurs at. If you want the behavior that you are describing, I would recommend directly using RhinoCommon to perform the boolean operations and then throw away the results instead of adding them to the document if an error occurs. The easiest way to do this is to look at the rhinoscriptsyntax function you are using and perform all of the same steps except adding of the results to the document when an error occurs.

Thank you for your answer. Unfortunately I’m not used to RhinoCommon at all … Would you have any advice or example to give me ?


Probably the best way to get started is to look at the rhinoscriptsyntax function that you are interested in getting results from without adding them to the document.

  • Set a breakpoint in the python script editor by clicking on the left border next to the function that you want to inspect (just left of the line number). You can tell a breakpoint is set when a red dot is shown. Clicking on the dot will remove the breakpoint.
  • Start your script
  • The script should pause execution at your breakpoint
  • You should now be able to step into the rhinoscriptsyntax function. Here you can see how the function is structured to use RhinoCommon. Stepping into the function is done by clicking on the button in the editor that has a tooltip of “Step In” (or use the Debug menu).

In addition to Steve’s answer, you can also still use rhinoscriptsyntax BooleanDifference and keep all the outputs, with the option rhinoscriptsyntax.BooleanDifference (input0, input1, delete_input=False)

Then keep track of what gets added to the document by it by adding to a list. When you need to go back, just delete all the contents of the list. If you need to keep the result, delete the input geometry (rather than the list).

Is this idea somehow useful?

1 Like

Oh damn you’re right, this is maybe way more simple (for me at least, for the moment) !

Thanks for all your answers ! I will check Plac’s method and come back to you if I have any issue. I will test Steve’s method if i have the time.