0
$\begingroup$

I`m try to set active scene thru python code that runs from cmd. bpy.context.window is always None in this case.

Can someone please explain why and if there is other ways to set active scene ?

$\endgroup$

2 Answers 2

0
$\begingroup$

The way to set the active scene is

bpy.context.window.scene = bpy.data.scenes['Scene']

replacing the right hand side of the assignment with whatever scene you want to use for the new context. See the Window page for details on the window type.

$\endgroup$
1
  • $\begingroup$ bpy.context.window is always None in this case. $\endgroup$
    – barakooda
    Commented Jun 1, 2022 at 15:31
0
$\begingroup$

In case someone gets None when using bpy.context.window consider use this solution:

def get_context_window():
   for window in bpy.context.window_manager.windows:
      if window:
         return window
   
   return None

import bpy

window = get_context_window()
scene = bpy.data.scenes.get('some_scene')

window.scene = bpy.data.scenes.get(scene)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .