Ruby, Undo Stack and dynamic components
-
Hey,
I'm working with using dynamic components in ruby. I'm able to set attributes and have them applied as such
ent.set_attribute(dict, key, value) # ... $dc_observers.get_latest_class.redraw_with_undo(ent)
However, doing so fills the undo stack with "Properties" and "redraw" operations, which is interfering with my own operation (which I start before the DC's are created and commit after the last redraw), as such
def some_func() #... Sketchup;;active_model.start_operation 'My Operation' create_ent() Sketchup;;active_model.commit_operation end #... def create_ent() ent = Sketchup;;active_model.entities.add_instance(definition, transformation) ent.set_attribute 'dynamic_attributes', 'some_key', 'some_value' # adds "Properties" to the undo stack #... $dc_observers.get_latest_class.redraw_with_undo(ent) # adds "Redraw" to the undo stack end
How can I ensure that my operation is the only one that appears in the undo stack, so that a single undo operation will remove all the ent, etc?
-
Have you explored the extra arguments to
start_operation()
?? -
instead of
redraw_with_undo( entity, progress_bar_visible=true )
you can also use this:redraw( entity, progress_bar_visible=true, is_recursive_call=false )
example in your module:
module Bowring def self.dc_redraw( ent, pbar_visible=true, undo=false ) # ldc = $dc_observers.get_latest_class() # if undo ldc.method(;redraw_with_undo).call( ent, pbar_visible ) else ldc.determine_movetool_behaviors(ent) DCProgressBar;;clear() ldc.method(;redraw).call( ent, pbar_visible ) DCProgressBar;;clear() ldc.refresh_dialogs() end # rescue TypeError => e # suppress nil to float conversion error that happens # when redraw is called directly with true 2nd arg. end #def end #module
-
@dan rathbun said:
@dan rathbun said:
Have you explored the extra arguments to
start_operation()
??instead of
redraw_with_undo( entity, progress_bar_visible=true )
you can also use this:redraw( entity, progress_bar_visible=true, is_recursive_call=false )
Combination of these was indeed the solution - thanks again
-
Another question on the undo stack, is it possible to prevent operations from appearing in the undo stack at all? To basically have transparent actions that are never added to the stack?
In certain cases I have to show/hide entities during an input stage, and that clutters the undo stack. It's possible to move them into one operation, but the stack looks something like
Operation 1 hide/show-operations Operation 2
Which adds an unnecessary undo step (as I undo all the operations performed in the ruby code).
-
You could try with the transparency flags of
.start_operation
.
Advertisement