Msgbus - How to subscribe to bpy.context.scene? I'd like to receive a msgbus notification when the active scene is switched, or somehow otherwise capture this event and respond to it in my code.
I thought this would be a fairly simple msgbus subscription to bpy.context.scene, but my listener is not receiving anything from msgbus, not even errors. In fact I don't seem to be able to get msgbus to fire for anything in bpy.context. What I was hoping for was something like an active property for bpy.types.BlendDataScenes that I can hook msgbus into, but I've come up blank and the lack of any kind of output from msgbus has left me fumbling in the dark with mittens on.
Has anyone been here before?
Subscribe to some event that signals scene change.
As with How to get an event when an object is selected?  find the code to change what you wish to notify.
In this case
Changing the scene
&gt;&gt;&gt; C.window
&lt;bpy_struct, Window at 0x7f842eee2f88&gt;

&gt;&gt;&gt; C.window.scene
bpy.data.scenes['Scene']

&gt;&gt;&gt; C.window.scene = D.scenes['Scene.001']
&gt;&gt;&gt; 

so in this case will try subscribing to the &quot;scene&quot; property of the Window class.
_I am not aware of anywhere that changing foo.scenes.active sets the context scene.  For example there is no bpy.data.scenes.active.
Search for other msgbus examples for other subscription to try.  AFAIK it is still the case that you cannot get notification of the instance object, so it is garnered from context.
import bpy
from mathutils import Vector, Matrix

handle = object()

# Triggers when widow's scene is changed
subscribe_to = bpy.types.Window, &quot;scene&quot; # 



def notify_test(context):
    print(context.scene.name)

bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(bpy.context,),
    notify=notify_test,
)

bpy.msgbus.publish_rna(key=subscribe_to)