Observer or Event when Changing Model
-
I realize that there is no way to capture the event when the user changes the current model BEFORE this happens, so that you can still do something about the current model.
Am I correct?
Note: there is an observer for BeforeSave, but you can change the model without saving.
Fredo
-
@fredo6 said:
Am I correct?
Generally yes. We have specifically asked for this observer callback. But have not yet been given it.
You can do periodic or strategically timed tests:
if @model != Sketchup;;active_model # Do something because @model is no longer active # but be most careful as changing non-active model # would likely crash SketchUp. end
or Ruby 2.0:
module Fredo6;;Refinement;;ActiveModel refine Sketchup;;Model do def active? self == Sketchup;;active_model end end end using Fredo6;;Refinement;;ActiveModel if @model.active? # do some stuff end
We also asked for
Sketchup::Model#activate()
so we can be sure that the model we wish to operate upon is activated.But it is not yet implemented either.
-
Dan,
Well, thanks for the confirmation. I think that what I am looking for is a Model.deactivate observer, that is the instant where the model will be taken off current context.
One small remark. I found that to check if the model has changed, you need to do
model1.path == model2.path
The reason is that I noticed in some occasion that you can have different handle for the same model. Here too, it would be good that the API has an explicit way to answer the question on whether the model was changed or not.
Fredo
-
@fredo6 said:
One small remark. I found that to check if the model has changed, you need to do
model1.path == model2.path
This can fail. If both model's are new models, and not yet saved, the
.path()
returns an empty string for both, which will eval as equal (true
.)@fredo6 said:
The reason is that I noticed in some occasion that you can have different handle for the same model.
But that was a bug in older SketchUp versions, wasn't it ?
I remember it happened when saving the model (most often.) But I thought it was fixed.
I also remember some programmers testing lower level collection references instead of the model references.
-
@dan rathbun said:
But that was a bug in older SketchUp versions, wasn't it ?
I remember it happened when saving the model (most often.) But I thought it was fixed.
Maybe, although I am not sure.
But as you know, supporting older versions is also a requirement, so that, as long as the old tricks work, you finally leave it as it is.Fredo
Advertisement