Is there a way to watch layer on/off events?

I would like to catch a layer table event and distinguish if the layer was turned off or on. I am using C++ SDK.

I overwrote virtual function LayerTableEvent which is triggered when a layer is changed. The first parameter of the function is CRhinoEventWatcher::layer_event event, and this enum has a single flag for any modification type (e.g., color changed, material changed, layer locked, etc.) and nothing specific to a layer being turned on/off. I am wondering, how can I distinguish this particular event? Maybe there are other ways to check this?

I haven’t yet accessed layers in code, so take this input for what it’s (not) worth :wink:

layer_modified sounds like the most promising type of layer event.

Does it not fire when the visibility or model visibility properties change? (that’s what you mean by active, right?)

If you want to track the changes in which are active/inactive I assume that you’d need to maintain an independent record of which are visible.

Thanks, Nathan. layer_modified does fire when visibility changes but it also fires when any other layer property changes. I needed to figure out how to distinguish visibility change from any other change.

I think I actually found a way to make it work. From the second function parameter I can get const CRhinoLayerTable& layer_table from which I can get the layer using layer index (3rd function parameter). Then comparing layer visibility with the previous layer state (4th function parameter - const ON_Layer* old_settings), I can find what was changed. So this works for me.

I was not sure initially what state the layer_table would have, the before-change (old settings) or after (new settings). Apparently, it is after change state, so comparison works. This is not described in any comments/docs, so I found this by trying.