I have a script that uses the entity observer to add an attribute to any new entities added to the model. I found that adding an attribute adds to the undo history. I’d like to add attribute to occur silently and either not allow it to be undone or package it up with the entity addition in the history queue.
Is this possible using the entity observer or should I be doing this differently?
You would need to wrap the attribute assignment inside an undo operation, and specify a transparent argument so that your operation is appended to the previous operation.
See API: Sketchup::Model#start_operation()
def add_attribute_to_entity( model, entity, value )
entity.set_attribute( @dict, @key, value )
Is there another way beside appending the operation we want to hide to another operation ?
I’m in the same situation as benwart, I’m saving some metadata in the model and i want to make that operation invisible to the user, so he can’t undo a simple set_attribute operation on the active model.
No, not really.
There is no guarantee the user (or some other cause, like an error,) will not undo the operation in which you have set the attribute(s).
The only thing I can think of is, a forced saving of the model to file. Saving clears the undo/redo stack.
You are not the first programmer to wish for setting some attributes outside the undo/redo stack.