I am trying to detect when the active scene changes.
Initially I tried using the message bus system to subscribe to bpy.types.Window, "scene"
Like this:
def callback():
print("changed")
owner = object()
subscribe_to = bpy.types.Window, "scene"
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=owner,
args=(),
notify=callback,
options={"PERSISTENT"}
)
This works when changing scenes manually or changing scenes from Python. However it does not trigger when a new scene is created and Blender switches to it automatically.
I then tried to add an application handler to the depsgraph_update_post
event and compare the number of scenes before and after the update as suggested in the comments here (Blender Python: Detect New Scene?). Unfortunately the app handler does not trigger either. I tested the configuration by adding an object to the scene and that triggers the handler.
Is this expected behavior? How can I detect the automatic scene change when a new scene is created.
Thanks in advance.