I'm currently trying to figure out how i can change the active view layer with python. The change to 2.8 made sourcing for documentation quite difficult.

I'd be thankfull for any help!

enter image description here


Set Window.view_layer

From https://code.blender.org/2017/09/view-layers-and-collections/

For simplicity now, we stick to having a single ‘active View Layer’ per Blender window.

Set the view_layer property of the context window to the view layer you wish to be active for that window.

Example using py console. I have 3 viewlayers "RenderLayer", "View Layer" and "XXXX", code below sets "XXXX" as active in current (context) window.

>>> vl = C.scene.view_layers['
                              View Layer']
>>> vl = C.scene.view_layers['XXXX']
>>> C.window.view_layer = vl
  • $\begingroup$ Thank you very much! It was far simpler than i imagined. Its essentially just: bpy.context.window.view_layer = bpy.context.scene.view_layers ['Layer_Name'] $\endgroup$
    – Chris
    Feb 15 '19 at 15:18
  • 1
    $\begingroup$ Possibly worth noting used to set context scene via context.screen.scene = scn, now that is also done via window also. context.window.scene = scn. $\endgroup$
    – batFINGER
    Feb 15 '19 at 15:24
  • $\begingroup$ sorry, that was just a misclick. It showed me that there has been an edit, so i've reloaded the page. After that it must have been unset again. Sorry! $\endgroup$
    – Chris
    Feb 15 '19 at 15:45
  • $\begingroup$ Cheers, didn't think it could be from changing "Render Layer" to "RenderLayer" lol. $\endgroup$
    – batFINGER
    Feb 15 '19 at 15:51
  • $\begingroup$ haha :D that would be quite harsh $\endgroup$
    – Chris
    Feb 15 '19 at 15:53

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.