# Ruby Stack Problem

**URL:** <https://forums.sketchup.com/t/ruby-stack-problem/36049>\
**Category:** Ruby API\
**Created:** [December 19, 2016, 4:56pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049 "2016-12-19T16:56:10Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [December 19, 2016, 4:56pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/1 "2016-12-19T16:56:10Z")

</div>

Does anyone know how to check the stack. I’m being told that I’m not kind to the stack. However, when I do a single rollback after running my plugin I can exit the program without saving. So sketchup itself doesn’t detect any changes.

---

<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:** [December 19, 2016, 5:42pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/2 "2016-12-19T17:42:38Z")

</div>

Do you mean the Ruby call stack or the SketchUp undo operation stack?

You can obtain the current call stack for Ruby using the Object#caller method.

I don’t think the SketchUp Ruby API provides any way to examine the SketchUp operation undo stack.

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [December 19, 2016, 7:25pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/3 "2016-12-19T19:25:17Z")

</div>

I’ll check it out.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [December 21, 2016, 1:15pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/4 "2016-12-21T13:15:14Z")

</div>

> [@gkernan](#):
>
> However, when I do a single rollback

Are you talking about the Undo stack?

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [December 21, 2016, 2:38pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/5 "2016-12-21T14:38:15Z")

</div>

I don’t exactly know. It would be an operation that affects the model that is outside a start\_operation and commit. But it doesn’t get picked up by sketchup as a change (doesn’t ask if I want to save)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [January 3, 2017, 11:53am UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/6 "2017-01-03T11:53:25Z")

</div>

I’m not quite sure what we are talking about here. But am I correct in guessing that you have submitted an extension to Extension Warehouse and been told there is some issues with how your extension manages the undo stack? Creates multiple undo operations for a user action?

Or are we talking about something else here?

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 3, 2017, 2:25pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/7 "2017-01-03T14:25:37Z")

</div>

I’ve added a feature that adds 1 dictionary attribute to a group or component. I didn’t think I would need to put a single operation into a start\_operation / commit since a single operation will get rolled back with a single undo.

I’ve now given my head a shake and put it inside a start\_operation / commit. Hopefully this satisfies some automated check that extension submissions undergo.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [January 4, 2017, 2:01pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/8 "2017-01-04T14:01:53Z")

</div>

When are you setting this attribute?

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 4, 2017, 4:24pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/9 "2017-01-04T16:24:30Z")

</div>

The user selects a single component that they want to include in the parts report.  
The user clicks the button to add to report.  
Then the user fills in the prompts of inputbox and accepts them.  
I build a single string containing those values and a few others and call set\_attribute for the selected component.

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [January 4, 2017, 9:59pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/10 "2017-01-04T21:59:41Z")

</div>

Even for a single action like that, an operation gives you control of what the user sees when undoing. It’s often more relevant than ‘Undo set attribute’ or whatever action that was performed.

```ruby
Sketchup.active_model.start_operation ("Add to Report")
cinst.set_attribute(...)
Sketchup.active_model.commit_operation

```

![](https://global.discourse-cdn.com/sketchup/original/3X/2/5/250736f26a5c23dcbe4a29a7c8345c4c24811bbb.PNG)

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 11, 2017, 5:38pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/11 "2017-01-11T17:38:04Z")

</div>

I keep submitting my cabmaker extension and it keeps coming back with the same error. I believe that I have all the entry points covered with start\_operation and commit\_operation.

ERROR: Attribute ‘dynamic\_attributes’/‘\_hasbehaviors’ set for # without an active operation.  
Source location: c:/users/cdeluca/appdata/roaming/sketchup/sketchup 2017/sketchup/plugins/su\_dynamiccomponents/ruby/dcclass\_v1.rbe:2808:in `set\_attribute’

Can’t you guys provide a bit more information? Like a trace back?

This extension has a lot of code. I do call set\_attribute from 4 functions. 1 of these functions called add\_part\_listing is called by 60 functions such as make\_side, make\_shelves, make\_stretchers, make\_doors etc…

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [January 11, 2017, 5:48pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/12 "2017-01-11T17:48:58Z")

</div>

Did you turn on debug\_mode? That will tell you when you leave the stack open.

```ruby
Sketchup.debug_mode = true

```

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 11, 2017, 6:16pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/13 "2017-01-11T18:16:26Z")

</div>

This is what I get in the ruby console - I’ve added a puts statement everywhere that I set a dictionary attribute.

> Sketchup.debug\_mode = true  
> true  
> start\_operation - prepare\_cabinet  
> add\_modify\_defaults set\_attribute  
> commit\_operation  
> start\_operation - do\_create\_cabinet  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_door\_listing set\_attribute  
> add\_interact set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_drawer\_box\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_door\_listing set\_attribute  
> add\_interact set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_part\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_hardware\_listing set\_attribute  
> add\_cab\_dict set\_attribute  
> add\_cab\_listing set\_attribute  
> commit\_operation  
> c:/users/public/documents/sketchup/gkware\_cabmaker/cabmaker.rbs:365: warning: Ruby operation left open: “Cab Maker”

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 11, 2017, 7:06pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/14 "2017-01-11T19:06:49Z")

</div>

Too funny. Now who’s calling the pot …

This comes straight from a dynamic component

> SketchUp: warning: Ruby operation left open: “Interact”

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [January 11, 2017, 8:25pm UTC](https://forums.sketchup.com/t/ruby-stack-problem/36049/15 "2017-01-11T20:25:34Z")

</div>

Took me most of the day but I have traced this Ruby operation left open to a line of code

I should mention that DYNAMIC is simply a constant assigned with ‘dynamic\_attributes’

> definition.set\_attribute(DYNAMIC, ‘onclick’, ‘animate(“y”, 0, -pullout)’)
