# A question about undo stack - external operation within my own start-commit

**URL:** <https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237>\
**Category:** Developers\
**Created:** [May 10, 2018, 12:20pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237 "2018-05-10T12:20:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ams](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ams](https://forums.sketchup.com/u/ams)\
**Post date:** [May 10, 2018, 12:20pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/1 "2018-05-10T12:20:52Z")

</div>

hello,  
i have read some topics about the following problem already, but found no answer,

so:

when i start an operation and create some geometry during this process (like a line following the mouse),  
i am still within this operation, unless i click for the second time and commit via  
model.commit\_operation.  
this work well.

but now i found out, that

after click 1 , which calls my own model. start\_operation,  
the user can for example

select another layer or create a layer and so on in skecthup menues (while he is inside my operation).

those actions themselves write into the undo-stack, as far as i can see  
and my commit does not work anymore.

please, can you give me any advice, how to solve this? is there a way to “remove entries” from the undo stack whithout undoing the “external” actions?

setting up observers does not help, since then the actions are already done.

thanx in advance for any help!

stan

ps: in this topic

[https://forums.sketchup.com/t/difficulties-wrapping-the-operations-of-a-plugin-into-one-undo/15657/2](https://forums.sketchup.com/t/difficulties-wrapping-the-operations-of-a-plugin-into-one-undo/15657/2)

greg wrote:

Francis,

As mentioned, you can combine all your operations. Also, you can create a counter for the number of operations added to the stack, then do

1.upto(cntr\_ops) { Sketchup.undo }

to remove them.

Greg

but i cannot apply this for now…(do not understand, how to implement the code)

---

<div class="post-metadata">

**Author:** ![eneroth3](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/eneroth3/32/1222_2.png) [@eneroth3](https://forums.sketchup.com/u/eneroth3)\
**Post date:** [May 10, 2018, 12:45pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/2 "2018-05-10T12:45:14Z")

</div>

I would recommend to start the operation, draw and commit directly after each other, without any paus in between.

---

<div class="post-metadata">

**Author:** ![ams](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ams](https://forums.sketchup.com/u/ams)\
**Post date:** [May 10, 2018, 3:18pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/3 "2018-05-10T15:18:53Z")

</div>

hi & thanx,  
the problem is, that this would litter the undo-stack, since the help-line is created more times with the mouse movement (preview), unless the endpoint is created.  
at the moment the whole thing is 1 operation (p2p).  
stan

---

<div class="post-metadata">

**Author:** ![eneroth3](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/eneroth3/32/1222_2.png) [@eneroth3](https://forums.sketchup.com/u/eneroth3)\
**Post date:** [May 10, 2018, 3:51pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/4 "2018-05-10T15:51:29Z")

</div>

If possible, avoid making any chances to the model until the user has finished making the input. For preview you can use the View#draw methods to only display a line, without physically adding it to the model.

---

<div class="post-metadata">

**Author:** ![ams](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ams](https://forums.sketchup.com/u/ams)\
**Post date:** [May 10, 2018, 6:19pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/5 "2018-05-10T18:19:57Z")

</div>

oh, thanx a lot, i did not know yet about this way of displaying lines ( i suppose, this type is not added to the undo stack !),  
i’ll report, if i manage it.  
thank you very much for the tip!  
stan

---

<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:** [May 10, 2018, 6:43pm UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/6 "2018-05-10T18:43:15Z")

</div>

> [@ams](#):
>
> is there a way to “remove entries” from the undo stack whithout undoing the “external” actions?

> [@Snapping to Temp Lines](https://forums.sketchup.com/t/snapping-to-temp-lines/68203/7):
>
> There is no current access (at all) to the undo / redo stack. The best you can do is use the transparent boolean arguments to [Sketchup::Model#start\_operation()](http://ruby.sketchup.com/Sketchup/Model.html#start_operation-instance_method).

> [@ams](#):
>
> after click 1 , which calls my own model. start\_operation,

Do **NOT** start the operation until after the 2nd click.  
As Julia said, use rubber-banding lines drawn on the view from the 1st point to the cursor.

See the SketchUp Team’s `"linetool.rb"` example in the Ruby Examples extension …

[http://extensions.sketchup.com/en/content/example-ruby-scripts](http://extensions.sketchup.com/en/content/example-ruby-scripts)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [August 10, 2018, 10:43am UTC](https://forums.sketchup.com/t/a-question-about-undo-stack-external-operation-within-my-own-start-commit/68237/7 "2018-08-10T10:43:16Z")

</div>

Closed on August 10, 2018, 10:43am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
