Model.X_operation
-
Is anybody using model.X_operation methods? Any pointers for when these are helpful?
Thanks!
-
@martinrinehart said:
Is anybody using model.X_operation methods? Any pointers for when these are helpful?
Thanks!
Yes.
model.start_operation('Cool Stuff', true) #lots of ruby work model.commit_operation
Now all the ruby work is grouped together so they are undone at at once. If you don't do this, and you draw ten lines, when you must undo ten times to get to the state before the operation.The first argument, the string, will be what you see in the Undo menu - "Undo Cool Stuff".
The second argument, (and third and fourth) is introduces in SU7. When the second is true, the SU UI is disabled until the nextmodel.commit_operation
. Which significantly speeds up scripts. But in order to make it SU6 compatible you must use version checking before calling it.you can use
model.abort_operation
in case you need error handling - you can use that when you encounter an error. -
Yeah, I use start_operation and abort_operation in pretty much every script. They work with the "undo stack". So if you write a script that loops 20 times and adds a line in each loop, SketchUp will count that as 20 separate operations. So to fix wthat, you can do:
` model.start_operation "Line Adder"
code to add my lines....
model.commit_operation`
By wrapping the code within the start and commit operations, it all just turns into a single commend. So ctrl-z (or EDit > Undo) will undo all 20 lines in one shot. AND the "Line Adder" text will be displayed in the Edit > Undo menu.
Chris
Advertisement