2
$\begingroup$

I would like to set the active scene with bpy.context.window.scene = my_scene

Now the problem is that normally this works if you are in the right context, the problem (in my specific case) is inside a function that is executed immediately after bpy.ops.render.render ('INVOKE_DEFAULT') immediately after the end of the render I get:

for s in bpy.data.scenes:
     if s == my_scene:
         context.window.scene = s

AttributeError: 'NoneType' object has no attribute 'scene'

so I guess currently the context has changed to that of rendering, am I wrong?

How can I solve this?

$\endgroup$
2
  • 1
    $\begingroup$ The issue here is context.window is None Similar to issue the other day in my deleted answer re closing render preview window. It seems somewhere the context gets "lost". Try windows = set(context.window_manager.windows[:]) before and after opening the render window. The difference will be the new window if one was opened. $\endgroup$ – batFINGER Jan 17 '20 at 15:26
  • $\begingroup$ @batFINGER I'd like to review your canceled answer, to better understand what you tried to do. I am doing an internet search and some tests with blender to see if I can find a solution. I no longer have that code because I haven't saved it $\endgroup$ – Noob Cat Jan 17 '20 at 18:11
0
$\begingroup$

I think the answer to my question is a simple copy of context. So:

ctx = bpy.context.copy()

bpy.ops.render.render('INVOKE_DEFAULT')

###This is handled with some handlers, but essentially seems to work with a simple context copy

for s in bpy.data.scenes:
     if s == my_scene:
         ctx['window'].scene = s

I think this is the answer to my question, but I won't vote for it right now as I could probably cheat in future problems. For now everything seems to work ok.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.