How to change bpy.context.scene inside a script?

Hi all,

I’m trying to change the value of bpy.context.scene. I read that

`
scene = bpy.data.scenes[1]

bpy.data.screens[“SceneName”].scene = scene

bpy.context.screen.scene=scene
`

is supposed to work, but I only noticed the change after the script had finished. I also tried using scene.update() in several places but it didn’t work.

Is it possible to do this?

mynewscene = bpy.data.scenes.new(name="MyScene")
context.window.scene = mynewsene

Do you mean

context.window.screen.scene

?

That works for me, so thank you! Any idea why that would work but screens[“Name”].scene wouldn’t?

I was assuming we are talking about 2.80. So I meant what I told you.
In 2.79 what you do is
bpy.context.screen.scene = scene

Yes, you are trying to pick a screen via a scene name.

Just do this, if you have to pick it by name:
bpy.data.scenes[“SceneName”]
or better
bpy.data.scenes.get(“SceneName”)

1 Like