Stuntkoala
(Simon Storl-Schulke)
September 14, 2021, 1:59pm
1
Basically I want my code to run every time I create a scene. I know that the messagebus system is probably the way to go, but I can’t get it to work. I can detect when the active scene is changed like this:
def callback_scenechange():
print("changed Scene")
owner = object()
subscribe_to = bpy.types.Window, "scene"
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=owner,
args=(),
notify=callback_scenechange,
options={"PERSISTENT"}
)
But this does not trigger whe I create a NEW scene.
Help would be appreciated
kkar
(kkar)
September 14, 2021, 5:05pm
2
I did not try this but maybe use
@persistent
def callback_scenechange():
print("changed Scene")
There are also
bpy.app.handlers.load_post
on loading a new blend file (after)
bpy.app.handlers.load_pre
on loading a new blend file (before)
Stuntkoala
(Simon Storl-Schulke)
September 15, 2021, 11:39am
3
thanks but this doesn’t trigger when creating a new scene - just when loading a blendfile.
Stuntkoala
(Simon Storl-Schulke)
September 15, 2021, 3:30pm
4
closing this because I decided to go with viewlayers instead (carries the same problems though)
kkar
(kkar)
September 15, 2021, 3:38pm
5
Interesting. In theory, a new scene is just loading the default scene.