I sometimes want to do some temporary manipulation of the contents of a model (e.g. adding or removing geometry for some analysis) and then restore the model to the original condition afterward without clutter on the undo stack. I can see two ways to do this: model#abort_operation, and model#commit_operation followed by Sketchup#undo.
Is there any advantage to one over the other, aside from the fact that undo requires first committing the operation, so it makes SketchUp do a lot more work. My sense is that abort_operation was meant to bail out when an exception occurs, but is there a downside to using it as a technique in other situations?
That said it’s best to avoid making model change unless necessary. Even if you don’t add anything to the undo stack you wipe the redo stack clean with this. I use the same technique myself sometimes, but whenever possible it’s good to avoid it.
(a) Would it be saving a copy of the model, opening it, doing the temporary changes, then closing and deleting the copy?
On Windows, the current model would need to be saved, because opening the copy replaces the current model. Instead of closing the copy, we’d just reopen the original then delete the copy.
Seems like a bit of a rigmarole. I would think that the undo and redo stacks would be blank at the end of this on Windows. On Mac they would perhaps be unchanged?
(b) Do a copy and paste of the target geometry into a new component definition context, do the changes inside, get the data, then delete the definition?
On Mac the undo/redo stacks are per-model and multiple models can be open in the same instance of SketchUp. So, yes they would be unchanged.
That’s an interesting idea. I’ll have to check, but I think it might leave transactions on the undo/redo stack. When I do this kind of thing, I always isolate the new geometry inside a Group or Component to prevent the added geometry from altering anything else in the model. So, if it leaves a clean stack, that would work.
BTW: the reason I have done this is for a particular client whose workflow destroys key information that my extension needs before they are ready to run it. I have to reconstruct what they deleted to do the analysis. I couldn’t persuade them to change their workflow, as that entangles with other things they do. So I implemented this workaround.