How to undo actions?

we make collection of action (moving rotating an scaling) and assign these to UI button .
when i undo it, its undo successive and make mistake.
how we can make it when i do undo , sketchup going back before clicked button??

Model.start_operation-instance_method

Model.commit_operation-instance_method

Sketchup.undo-class_method

3 Likes
Sketchup.active_model.start_action("MyAction", true)

### add your main code here

Sketchup.active_model.commit_action

If you include Sketchup.active_model.abort_action anywhere in your main code it undoes everything your code has done so far, remember to add after the abort_… return nil to stop further execution of the commit_…

1 Like

I don’t think if there are such a methods.

2 Likes

You are right - brain fart !
‘action’ should read ‘operation’ !
I muddled it up with other API’s code - I’m tired !! :upside_down_face:

Here’s what it should have said;

Sketchup.active_model.start_operation("MyAction", true)

### add your main code here

Sketchup.active_model.commit_operation

If you include Sketchup.active_model.abort_opertation anywhere in your main code it undoes everything your code has done so far, remember to add after the abort_… return nil to stop further execution of the commit_…

2 Likes