Hi there,
I am developing an extension where users use the extension exclusively to do all the operations. I am now facing problems with undo/redo.
Quick overview of the extension. There are predefined models in an HTML window that the designer drags and drops to the SketchUp model. After dropping the model using a new window the designer can update the dropped model(like width, height, add few things to the model. All from the configuration window.).
I have Sketchup.active_model.start_operation and Sketchup.active_model.commit operation at correct places but I still see a bunch of other transaction on the undo/redo stack. I dug a little deeper and found that few Sketchup operations create a transaction on there own like Sketchup.active_model.set_attribute and Sketchup.active_model.active_entities.erase_entities.
Q: Is there a way to avoid having these extra transactions on the undo/redo stack. Maybe I can club them with my transaction so that the end-user can use a smooth and organic operation.
Every single operation what causing model to change, will be recorded to undo stack.
It is a developer responsibility to wrap multiple model changes caused by the same user action into a single undo operation using Sketchup::Model#start_operation and Sketchup::Model#commit_operation.
Actually you can make not only one but more “own club” of undo operations, if your tool is complex and you feel it is necessary.
If you do not include an operation what caused a model change that will be still recorded and will shown as independent Undo action on UI.
So, no, it is not possible to avoid extra transactions and yes, please “*club them* with your transaction so that the end-user can use a smooth and organic operation.”
Yes there are both some API calls and native features that will close any current operation (an undo step) and start their own. Model#place_component is one of these quirky features.
To “club”, or combine these operations with your own operations, you need to use the 3rd and 4th transparent arguments to the Model#start_operation method.
Is there any list that has all the Sketchup APIs that start a transaction of their own? Like the Sketchup.active_model.active_entities.erase_entities or Model#place_component
Every API call that makes a “physical” change to the model (i.e. not things like moving the camera or changing the model-wide display settings) adds to the undo stack. The methods you list are no exceptions but follow the general rule. Calls for starting and committing an operations makes all these small transaction display to the user as just one big change in the undo stack. This is also how the user would think of a model change that they trigger with e.g. a click, even if the operation internally takes several transactions to carry out.
Maybe you could describe at a higher level what you are trying to achieve and what is confusing you?