# Cancel multiple methods with a single undo in SketchUp

**URL:** <https://forums.sketchup.com/t/cancel-multiple-methods-with-a-single-undo-in-sketchup/61104>\
**Category:** Ruby API\
**Created:** [February 2, 2018, 2:53pm UTC](https://forums.sketchup.com/t/cancel-multiple-methods-with-a-single-undo-in-sketchup/61104 "2018-02-02T14:53:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [February 2, 2018, 11:22pm UTC](https://forums.sketchup.com/t/cancel-multiple-methods-with-a-single-undo-in-sketchup/61104/2 "2018-02-02T23:22:55Z")

</div>

Giving us an example with _bogus_ method names does not help. _So I have to guess_ …

* * *

There are **certain methods** in the API that commit their **own** operation and **cannot** _easily_ be nested in a Ruby operation.

These cases have already be discussed here in the forum,  
and logged as issue in the [official _public_ API Issue Tracker](https://github.com/SketchUp/api-issue-tracker/issues).

Notable methods are [`DefinitionList#load`](http://ruby.sketchup.com/Sketchup/DefinitionList.html#load-instance_method) and [`Model#place_component`](http://ruby.sketchup.com/Sketchup/Model.html#place_component-instance_method).

_SEE:_

> <https://github.com/SketchUp/api-issue-tracker/issues/6>
>
> The \`next\_transparent\` parameter for \`Model#start\_operation\` needed.  
> 
> The \`M…odel#start\_operation\` method provides some control for plugin developers over the SketchUp undo stack. It has four parameters:
> 
> \- \_op\_name (String)\_ 
> \- \_disable\_ui (Boolean) (defaults to: false)\_
> \- \_next\_transparent (Boolean) (defaults to: false)\_ 
> \- \_transparent (Boolean) (defaults to: false)\_
> 
> The \`next\_transparent\` parameter is currently marked as ‘Deprecated’ in the API documentation and even has a ‘Use with extreme caution’ label. We have found ourselves in situations where we cannot do some operations without the \`next\_transparent\` argument set to true.
>  
> For example, when we want to load a component from a file and place it into the model. We do it when a user presses a button on the toolbar - so we want that the loading and the placement appear as a single operation in the undo stack. 
> 
> The following code example loads and places the component, but it commits two operations into the undo stack:
> 
> \`\`\`ruby
> model = Sketchup.active\_model
> component\_def = model.definitions.load(path\_to\_component\_file)
> model.place\_component(component\_def)
> \`\`\`
> 
> We can try and make the \`#place\_component\` invocation transparent:
> 
> \`\`\`ruby
> component\_def = model.definitions.load(path\_to\_component\_file)
> model.start\_operation "Loading and placing component",
> transparent=true
> model.place\_component(component\_def)
> model.commit\_operation
> \`\`\`
> 
> But this doesn’t work, because operations in SketchUp cannot be nested. 
> 
> The following solution resolves the problem:
> 
> \`\`\`ruby
> model.start\_operation "Transparent component placement",
> disable\_ui=false,
> next\_transparent=true,
> transparent=false
> component\_def = model.definitions.load(path\_to\_component\_file)
> model.commit\_operation
> model.place\_component(component\_def)
> \`\`\`
> 
> Since both \`Model#place\_component\` and \`DefinitionList#load\` methods commit operations into the stack and operations cannot be nested, it’s impossible to unite their invocation into one operation without the next\_transparent parameter. 
> 
> Please make sure not to remove this parameter in future versions of the Sketchup API.

Also, I had posted an example that uses [`Model#place_component`](http://ruby.sketchup.com/Sketchup/Model.html#place_component-instance_method) in one undoable operation …

> [@\[code\] undoable place\_component() "MoveTool" clone](https://forums.sketchup.com/t/code-undoable-place-component-movetool-clone/27193):
>
> Continuing the discussion from: [Model.place\_component component\_definition, boolean cannot be undone?](http://forums.sketchup.com/t/model-place-component-component-definition-boolean-cannot-be-undone/17165): Here is an example of a single undoable place component operation. It is not a tool, rather it is a command. It achieves the single undo, via 3 linked operations. The first is attached to the following model#place\_component() operation, and the last is attached to it’s predecessor. It can move both compound (groups, images and component instances,) and primitive objects. [move\_selection\_se…](https://forums.sketchup.com/uploads/short-url/llfZG7k6oVZGf4L0mFjN4KAXWe3.rb)

---

_[View the full topic](https://forums.sketchup.com/t/cancel-multiple-methods-with-a-single-undo-in-sketchup/61104)._
