Observe instances / groups being hidden/shown


Is there a way using the Ruby API to observe when an instance or a group is hidden / shown either directly with .hidden = true / false or by it’s tag being hidden / shown?


You can ask entities if they are hidden with Class: Sketchup::Drawingelement — SketchUp Ruby API Documentation
And set the new status with
Class: Sketchup::Drawingelement — SketchUp Ruby API Documentation

: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:

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

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…
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…

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…


Thanks dezmo, it’s way more complicated than I thought!

I’m creating an Overlay that highlights component instances with a given state (stored as an attribute) using view.draw(GL_TRIANGLES, …) and I obviously don’t want to highlight anything that’s not visible. And since I want to cache the triangles for performance I wanted to find out when the visibility of instances changed.

I’ll look into #drawing_element_visible? at least.

1 Like