Undo Script if result is null of esc is press Rhino Python


(Matt Gaydon) #1

Morning All,

I have written a code that first checks if layers are present and deletes the ‘old’ clipping planes and objects within selected group, then lets the user pick a new box for the clipping planes to be defined by.

If the user esc’s the command it exits the script but does not undo the changes done in the code above it.

What do I need to add to the code here so it returns the file before the code was run with all the old clipping planes or if its the first time without the layer and group

boxpts = rs.GetBox(0)
if boxpts is None :return

Thanks
Matt


#2

Why first delete stuff and be able to cancel later? Why not ask before deleting stuff and when accepted do it?
Or even. Dont delete stuff until last?


#3

Normally just hitting “undo” will undo anything the script has done - as long as the operations in the script are those that would normally go on the undo stack. Not all operations are, things like view changes are not undo-able with undo, you would have to record those separately.

As jordy said, if you’re really worried about this, keep all the objects until the very last - hide them if you need them to disappear, and then as the script finishes, delete them.

–Mitch


(Matt Gaydon) #4

Thinking about it its I can work out how to disable the clipping planes then wouldn’t need to be deleted them until the end of the script, I am guessing this would be via Script Context??