4
$\begingroup$

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

$\endgroup$

1 Answer 1

4
$\begingroup$

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['
                              RenderLayer']
                              View Layer']
                              XXXX']
>>> vl = C.scene.view_layers['XXXX']
>>> C.window.view_layer = vl
>>> 
$\endgroup$
5
  • $\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
    Commented Feb 15, 2019 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
    Commented Feb 15, 2019 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
    Commented Feb 15, 2019 at 15:45
  • $\begingroup$ Cheers, didn't think it could be from changing "Render Layer" to "RenderLayer" lol. $\endgroup$
    – batFINGER
    Commented Feb 15, 2019 at 15:51
  • $\begingroup$ haha :D that would be quite harsh $\endgroup$
    – Chris
    Commented Feb 15, 2019 at 15:53

You must log in to answer this question.

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