New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModelObserver#onDeleteModel is not called when closing a model #717
Comments
I do NOT see either the delete nor erase callback being called on Windows. My test: class ModelSpy < Sketchup::ModelObserver
def self.spy
Sketchup.active_model.add_observer(new)
end
def onDeleteModel(model)
puts "#{self.class.name}: #{__method__} called"
end
def onEraseAll(model)
puts "#{self.class.name}: #{__method__} called"
end
def respond_to?(meth)
puts "SketchUp is polling #{self.class.name} for a #{meth} callback."
super
end
end |
For Mac, there is the On Windows, since there is only ever one model object open at a time, the So I could suggest that you attach your extension submodule to the SketchUp application as an * An observer object can be any type of object as long as the callback methods are publicly accessible. So a module can serve well as the |
@DanRathbun Yes, we use However, we're still missing a way to cleanly detect the closure of a model, which can happen easily on Mac. Unfortunately, it seems that For the moment, we ended up with a UI timer constantly polling model.valid? + many defensive checks (imagine |
Yea, |
Also if the model has modifications, when calling If the user answers Yes then we get the usual procession of observer calls ... Sketchup.active_model.close ... output from the above
|
I still see no calling of Sketchup.active_model.entities.clear! At the same time it looks like class ModelSpy < Sketchup::ModelObserver
def self.spy
ispy = new()
Sketchup.active_model.add_observer(ispy)
Sketchup.active_model.entities.add_observer(ispy)
end
def onDeleteModel(model)
puts "#{self.class.name}: #{__method__} called"
end
def onEraseAll(model)
puts "#{self.class.name}: #{__method__} called"
end
def onEraseEntities(entities)
puts "#{self.class.name}: #{__method__} called"
end
def respond_to?(meth)
puts "SketchUp is polling #{self.class.name} for a #{meth} callback."
super
end
end We get this weird output with a new model and only a Sumele instance ... Sketchup.active_model.entities.clear!
Perhaps the ... and deprecated for the |
It would be helpful for the documentation to explain just when and why these two observer callbacks will or won't fire. |
Logged as: SKEXT-3255 |
Hi,
We're unable to use
ModelObserver#onDeleteModel
in our extension to react to a model being closed.From the documentation, I expected this callback to be executed when closing a model (might have misunderstood the doc; the difference between "delete" and "close" is unclear to me in that context).
Here's a reproducer:
Our use case
We need to detect the model closing on Mac to:
Right now, the dialogs are not closed because the aforementionned callback cannot be used to do so. Naturally this leads to many errors down the line because the model and the entities that are referenced in the code backing those dialogs do not exist anymore.
Do you know of another way to detect if a model has been closed without polling its
.valid?
method in every spot where the model/its entities are referenced?Thanks!
The text was updated successfully, but these errors were encountered: