I tried this
subscribe_to = (bpy.types.ViewLayer, "active_layer_collection")
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=bpy,
args=(None,),
notify=update,
)
I also tried these:
subscribe_to = (bpy.types.Context, "collection")
subscribe_to = (bpy.context, "collection")
subscribe_to = (bpy.context.view_layer, "active_layer_collection")
...
And more, they don't work.
How to be notified when the active collection changes?
Another question: when
context.selected_objectschanges, get notified.
subscribe_to = (bpy.types.LayerObjects, 'selected')
subscribe_to = (bpy.context, 'selected_objects')
...
It doesn't work either.
msgbusunfortunately often doesn't work. You can use the Application Handler instead, and on every change check if what you're interested in has changed. I show this technique (though not using app handler) here: Driver based on shading types/ change boolean when switching shading types – Markus von Broady Oct 04 '22 at 15:06SpaceOutliner.draw_handler_add(update, (), 'WINDOW', 'POST_PIXEL')This works. – Kayon Oct 05 '22 at 04:40