How can I set the active view layer via Python?

I’d like to create a new view layer via Python and make it the active one. I can create the view layer using bpy.context.scene.view_layers.new(name='myLayer'), but how would I make it active? bpy.context.view_layer is read-only, and so far I could not find something like active_view_layer anywhere.

You can set view layer using context.window.view_layer = my_view_layer.

3 Likes