So I have an action on my plugin that sets multiple attribute dictionary value via the set_attribute
command. This populates my undo list because every attribute that I add it adds Undo property
is there a way to make this a single operation? What I want is to undo all the set_attribute
in one undo or merge it on another open operation so that If I undo it would be on one undo only
Check this methods:
The #start_operation method is used to notify SketchUp that a new operation (which can be undone) is starting. ( take a look especially the last parameter )
The #commit_operation method commits an operation for undo.
The #abort_operation method aborts the current operation started with the start_operation method.
Thanks I actually have that on my method basically I an existing method do_somemore_things
and I just wrapped it up with this im expecting to make this a single action on the history but currently it gives me multiple things.
def something
model = Sketchup.active_model
model.start_operation "Add all attributes", true, true, false
do_somemore_things
model.commit_operation
end
What im seeing are multiple Add attribute
then Set Texture
then Add Texture
which are correct because these are the actions that Im doing inside the do_somemore_things
method
Now, I’m not sure if I understood right…
-
You are saying that in your
do_somemore_things
method you are doing “everything” that you need to be undo at once. Then you do not need a 3rd and 4th argument instart_operation
method. (These are defaulting tofalse, false
)
Actually the 3rd line above should looks like:
model.start_operation "Add all attributes", true
and this should wrap all “things” into one undoable operation.
Perhaps we need to see your code what are yourdo_somemore_things
method really does. -
The 3rd parameter is anyway Deprecated!. (Which normally Indicates that the method is deprecated and will be removed in a future version. ) I’m not sure if (or at all) influencing, but I would put
false
there. (also because the documentation warns that it is very “difficult one”…) . -
Normally if you want to chain the operations in to single one, I guess, a pattern should be like this:
model.start_operation('My operation', true)
do_some_things
model.commit_operation
# The operation name won't be matter it will chained to previous op.
model.start_operation('...', true, false, true)
do_someother_things
model.commit_operation
# The operation name won't be matter it will chained to previous op.
model.start_operation('...', true, false, true)
do_somemore_things
model.commit_operation
- If you are inside an observer see the example in the #start_operation method documentation.
Edit:
- The SketchUp Free (web) version - as your profile indicates - does not support any of the methods mentioned above… . Please fill up your forum profile with proper (valid) data.
Don’t use the third or fourth argument in start_operation
unless you know you need it. (In fact, don’t use the third one at all.)
Also note that the string passed to start_operation
is user visible in the Edit - Undo menu, so take that into consideration when crafting the string.
Can you post a complete example that reproduce this?