Observe instances / groups being hidden/shown

:thinking: Unfortunately, it won’t be that easy. I guess.

In this case perhaps you need to check if visible given by the current model options:
Sketchup::Model#drawing_element_visible?(instance_path)

Unfortunately (again), if you check this topic there are some problems in conjunction with the InstancePath. (Not to mention the visibilities by scenes…)

Moreover:
You may also attach InstanceObservers to the instance in question then the #onChangeEntity method will fire if the instance visibility is about to change. But it will not fire if the visibility of potential parent instance is changed. So you need to listen that too…
AND:
The visibility of the instance also depends of the visibility of the assigned Tag.
So may need to attach a LayersObserver to that Tag (layer) and listen if the #onLayerChanged method fires, then check if the visibility and instance is involved…


Edit:
Thinking further (… complications):
When the observer(s) fires, you can only query the current visibility status, so it must be stored somewhere (e.g. in attribute) so that you can compare the previous and new statuses…

3 Likes