Sketchup Undo going to far


#1

I have the following code:

Sketchup.active_model.start_operation "MoveSelectedToNewGroup"
# code
Sketchup.active_model.commit_operation
# Save copy of file
Sketchup.undo

When I run this code it undoes the last thing the user did in Sketchup. How can I make it only undo the code in between the operations?


#2

You can’t undo a save as the file has ‘escaped’ from SketchUp’s control !
If you want to change the model, then save it, but then discard those changes, then you need to use this format…

### Point A
model.start_operation("SomeOperation", true)
  ### Make some changes to the model
  ### Make a copy of the changed model
model.abort_operation
### Point B

That should change the model, make a copy of it [including the changes], but then by “Point B” it has returned the model to the state it was at “Point A”.