# Change active View Layer with Python

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!

Set Window.view_layer

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
>>>

• 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'] Feb 15 '19 at 15:18
• 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. Feb 15 '19 at 15:24
• 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! Feb 15 '19 at 15:45
• Cheers, didn't think it could be from changing "Render Layer" to "RenderLayer" lol. Feb 15 '19 at 15:51
• haha :D that would be quite harsh Feb 15 '19 at 15:53