Determining when a model has changed
-
We have some code we want to run whenever a user starts a function, but the model has changed since the last time it was started.
- Either by using SketchUp "New", or "Open", or by adding new geometry.
We have been using two "tricks" to determine if the model has changed since we last checked it.
- We write a UUID as an attribute to the model, then check to see if the UUID has changed.
- that catches New and Open. But can get messed up if the model is saved with a new name, for example, and changed, saved, and then then first model is loaded, so we added #2.
-
We remember the name and path of the model and check it to see if it has changed.
-
We plan to remember the number of entities in the model as well, so we can tell when new entities have been added. (But, of course, this will not catch those cases where one entity was deleted and one new entity was added)
It does not hurt for us to run the routine we run when the model has changed - but it can take a few seconds, (or longer), so we don't want to run it too often.
Does anyone have any ideas on how to determine if the model has been changed?
-
https://developers.google.com/sketchup/docs/ourdoc/model#modified?
The
model.modified?
method determines if the Model has been modified since the last save. -
The
model.modified?
method determines if the Model has been modified since the last save.[/quote]Thanks for the quick response TIG.
That would work if there was a "saved" Observer, (so I could remember that the model had been saved, and set a semiphore to remember that it had been saved) (It wouldn't hurt to re-run my routine once per save)
Also, the changes I make after performing my check for changes would set the modified? tag, and confuse me. (and I don't want to reset the modified? value, or to save the model)
-
@al hart said:
@tig said:
The
model.modified?
method determines if the Model has been modified since the last save.That would work if there was a "saved" Observer, ...
The "saved" callbacks are in the Sketchup::ModelObserver class (where they should be, because there can be more than one model open on the Mac. But you can write a generic model observer that handles all open model instances, since the model instance's reference is passed to most callbacks.)
Advertisement