# Undo vs abort operation?

**URL:** <https://forums.sketchup.com/t/undo-vs-abort-operation/330414>\
**Category:** Ruby API\
**Created:** [June 7, 2025, 2:56pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414 "2025-06-07T14:56:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [June 7, 2025, 2:56pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414/1 "2025-06-07T14:56:53Z")

</div>

I sometimes want to do some temporary manipulation of the contents of a model (e.g. adding or removing geometry for some analysis) and then restore the model to the original condition afterward without clutter on the undo stack. I can see two ways to do this: model#abort\_operation, and model#commit\_operation followed by Sketchup#undo.

Is there any advantage to one over the other, aside from the fact that undo requires first committing the operation, so it makes SketchUp do a lot more work. My sense is that abort\_operation was meant to bail out when an exception occurs, but is there a downside to using it as a technique in other situations?

---

<div class="post-metadata">

**Author:** ![ene\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/ene_su/32/103091_2.png) [@ene\_su](https://forums.sketchup.com/u/ene_su)\
**Post date:** [June 17, 2025, 2:10pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414/2 "2025-06-17T14:10:53Z")

</div>

abort\_operation can be used for this.

That said it’s best to avoid making model change unless necessary. Even if you don’t add anything to the undo stack you wipe the redo stack clean with this. I use the same technique myself sometimes, but whenever possible it’s good to avoid it.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [June 17, 2025, 3:10pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414/3 "2025-06-17T15:10:01Z")

</div>

So what is the alternative?

**(a)** Would it be saving a copy of the model, opening it, doing the temporary changes, then closing and deleting the copy?

On Windows, the current model would need to be saved, because opening the copy replaces the current model. Instead of closing the copy, we’d just reopen the original then delete the copy.

Seems like a bit of a rigmarole. I would think that the undo and redo stacks would be blank at the end of this on Windows. On Mac they would perhaps be unchanged?

**(b)** Do a copy and paste of the target geometry into a new component definition context, do the changes inside, get the data, then delete the definition?

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [June 17, 2025, 3:17pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414/4 "2025-06-17T15:17:43Z")

</div>

> [@DanRathbun](#):
>
> On Mac they would perhaps be unchanged?

On Mac the undo/redo stacks are per-model and multiple models can be open in the same instance of SketchUp. So, yes they would be unchanged.

> [@DanRathbun](#):
>
> **(b)** Do a copy and paste of the target geometry into a new component definition context, do the changes inside, get the data, then delete the definition?

That’s an interesting idea. I’ll have to check, but I think it might leave transactions on the undo/redo stack. When I do this kind of thing, I always isolate the new geometry inside a Group or Component to prevent the added geometry from altering anything else in the model. So, if it leaves a clean stack, that would work.

BTW: the reason I have done this is for a particular client whose workflow destroys key information that my extension needs before they are ready to run it. I have to reconstruct what they deleted to do the analysis. I couldn’t persuade them to change their workflow, as that entangles with other things they do. So I implemented this workaround.

---

<div class="post-metadata">

**Author:** ![Fredo6](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fredo6/32/77024_2.png) [@Fredo6](https://forums.sketchup.com/u/Fredo6)\
**Post date:** [June 17, 2025, 7:47pm UTC](https://forums.sketchup.com/t/undo-vs-abort-operation/330414/5 "2025-06-17T19:47:10Z")

</div>

> [@ene\_su](#):
>
> That said it’s best to avoid making model change unless necessary. Even if you don’t add anything to the undo stack you wipe the redo stack clean with this.

It would be more accurate that the redo stack is wiped out at the `model.commit_operation` rather than at the `model.start_operation`.
