Consider this code:
bpy.context.screen.scene = bpy.data.scenes.new("My Scene")
print("Active scene is",bpy.context.scene)
- When this is executed line-by-line from the console, the UI shows the new scene and context.scene becomes the scene we just created.
- When it is executed from a script, the UI shows the new scene but context.scene does not change from its original value.
This is in r30581, and the problem has been reported as far back as 27070.
Description
Description
Event Timeline
Hello. No idea if this'll be heard, but I've been looking around for an answer and not getting anywhere.
I'm basically trying to do the same thing as Tom was - setting a scene, but bpy.context.scene doesn't update immediately. Is there a known way now to force another event loop or wait or something? Something to make bpy.context.scene update immediately?
Wow, a bug report from seven years ago! Since then I've discovered how to wait for the next event loop:
import bpy def scene_update(scene): print(scene.name) bpy.app.handlers.scene_update_post.remove(scene_update) def hook_scene_update(callback): bpy.app.handlers.scene_update_post.append(callback) hook_scene_update(scene_update) bpy.context.screen.scene = bpy.data.scenes[1]