Ruby Stack Problem


#1

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.


#2

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.


#3

I’ll check it out.


#4

Are you talking about the Undo stack?


#5

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)


#6

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?


#7

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.


#8

When are you setting this attribute?


#9

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.


#10

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.

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


#11

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…


#12

Did you turn on debug_mode? That will tell you when you leave the stack open.

Sketchup.debug_mode = true

#13

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”


#14

Too funny. Now who’s calling the pot …

This comes straight from a dynamic component

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


#15

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)’)