View layers have no index anymore?

I’m trying to bring the Move Render Layers addon back to life. And since the view layers don’t have a template_list like render layers used to, I’m trying to add that too.

I did a first draft in, but I meet an issue: I need to access the view layer’s active_index, but they don’t seem to exist in modern Blender:


This is used in def moveViewLayer to change the view layers, as well as in the template_list definition.

Or at least, this is what the original addon used to work with to manage the render layers order in the list.

All I get when running my script are errors like:

Traceback (most recent call last):
  File "C:\AppInstall\Blender\stable\blender-3.3.1-windows-x64\3.3\scripts\modules\", line 904, in draw_ls
    func(self, context)
  File "C:\Users\Roikku\Documents\Repositories\Move-View-Layers\Workbench\test.blend\", line 285, in ViewLayerMoveButtons
AttributeError: 'RenderSettings' object has no attribute 'layers'

Is there an equivalent I can use instead? Or another method to do basically the same thing?

With bpy.context.view_layer you can get the active view layer.
It’s a read-only property, so how you can set the active layer, I don’t know.

Edit: I found out that for the active window you can set the active view layer with bpy.context.window.view_layer = bpy.context.scene.view_layers['YourViewLayer'].

I am looking for the index of view_layers, which used to be stores in active_index before Blender 2.80.

def view_layer_index(view_layer):
    for i, view_layer_search in enumerate(bpy.context.scene.view_layers):
        if view_layer_search == view_layer:
            return i


Thanks, but I’m afraid I don’t see how this would help.

The end goal is to manage the order of View Layers. This used to be done before 2.8 using the layers’ active_index, which is what defined the View Layers’ order and could be incremented or decremented.

That’s what happens in def moveViewLayer.

I am looking for a way to reproduce that end goal. The active_index as it existed until v2.79 seems to be gone, so either there’s a new way to access it or an equivalent, or I need to find a completely different method to reorder View Layers. I don’t need to calculate what’s their position in the list, I need to change it.

It never was possible to reorder stuff using active_index - it exists so that UI lists can have a selection.

What the addon you’re updating did, was that it brute copied all properties and renames view layers between them, emulating that the view layers changed order. The UI list active index was used as a reference point to decide whether the selected view layer would be moved up or down. The active index itself is based on the data block order @Gorgious showed.

1 Like

Oh… Thanks for the explanation, that makes sense :o Sorry for the misunderstanding.

I will keep you posted on my progress.


I’ve managed to get the operator working. Now we must figure out the UI: where to place the buttons?

1 Like

Oh wow! Congrats on that!

My first idea was to re-implement what we used to have back in 2.79 and before:

I kind of partially did it in is you want to have a look at it.