onClose event

Hi!, I’m looking for an event similar to ‘onSave’ (from class: Sketchup::ModelObserver), but I want to capture the event ‘onClose’ that runs when I do this:


Is that possible?

On Windows there can only be one model open at a time in each SU session, so here you can use AppObserver#onNewModel and AppObserver#onOpenModel to detect a model closing.

I don’t know exactly what corresponds to this on Mac but if you cache a reference to the active model, perhaps onActivateModel could be used to test if that cached model is still valid, and otherwise assume it was closed.

Rgere is also an onQuit method that fires when SketchUp is closed if that is what you are after.

There is no such event. May I ask what you are looking to do with such an event?

The ModelObserver has an onDeleteModel callback. The documentation is however quite unclear about when it fires.

The #onDeleteModel method is invoked when a model is deleted.

I think this is one of those events that just got hooked up back the the days without much testing. I don’t think I’ve been able to trigger this one myself. If I recall correctly it’s theoretical trigger happened as things where destroyed and model observer already removed.

It sounds like it is a bug that needs to be fixed.

Ie, it should fire before the observer is removed, and before the model is destroyed, so as to signal the imminent destruction of the model object to observers so that they can save state, etc. Meaning this callback must obviously be an “onBefore” type of callback because we cannot respond to (or read anyting from) an object that is already gone.

I feel sorry for the onDeletedModel callback :frowning: .