Python API: Add new method to move view layers #117037

Merged
Brecht Van Lommel merged 2 commits from pioverfour/blender:dp_move_view_layers into main 2024-01-12 16:34:47 +01:00

2 Commits

Author SHA1 Message Date
Damien Picard d39f79b032 Fix build error
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
2024-01-12 16:06:59 +01:00
Damien Picard 4e520affb4 Add new method to move view layers
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
View Layers currently cannot be reordered, forcing Python programmers
to remove and recreate them if they want to sort them.

This commit adds a new method `Scene.view_layers.move()`. It acts the
same as `Object.modifiers.move()`, taking two arguments `from_index`
and `to_index`.

Layers could then be reordered like this, for example:

``` python
import bpy

scene = bpy.context.scene

layer_names = scene.view_layers.keys()
sorted_layer_names = sorted(layer_names)

for l_i, l in enumerate(sorted_layer_names):
    scene.view_layers.move(scene.view_layers.keys().index(l), l_i)
```
2024-01-11 17:49:54 +01:00