right now only there's the possibility of creating new view layers, but every time you create a view layer it defaults all layers to visible, and sometimes in the scene there are views that are too similar and when you got a lot of collections it gets painful to adjust the same over and over. Is there a way?

  • $\begingroup$ It works fine on my blender 2.81 I ran the script and a copy of the wiewlayer was created with its atributes. Thanks a lot $\endgroup$ – DAVID TERES Nov 4 at 19:22

This little script lets you duplicate a view layer with its visibility settings only, render passes and cycles settings, render and selectable are settings that are shared among all layers.

import bpy
context = bpy.context
old_layer = context.window.view_layer
new_layer = context.scene.view_layers.new(old_layer.name)
collection = old_layer.layer_collection
new_collection = new_layer.layer_collection

for prop in dir(new_layer):
        attr = getattr(old_layer,prop)
        setattr(new_layer, prop, attr)

cycles = old_layer.cycles
new_cycles = new_layer.cycles
for prop in dir(new_cycles):
        attr = getattr(cycles,prop)
        setattr(new_cycles, prop, attr)

def recursive_attributes(collection, new_collection):
    new_collection.exclude = collection.exclude
    new_collection.holdout = collection.holdout
    new_collection.indirect_only = collection.indirect_only
    new_collection.hide_viewport = collection.hide_viewport

    for i, _ in enumerate(new_collection.children):
        old_child = collection.children[i]
        new_child = new_collection.children[i]
        recursive_attributes(old_child, new_child)

    for i, _ in enumerate(new_collection.collection.objects):
        tmp = collection.collection.objects[i].hide_get()

    return 0

recursive_attributes(collection, new_collection)
context.window.view_layer = new_layer

thanks for the code, I tried it, and it gave bunch of errors of unexpected indents, and duplicated the view layer, but didn't respect the collections checkmarks, bascially just added a new view layer with copied name of the active layer. :/

  • $\begingroup$ This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. $\endgroup$ – Grimm Oct 2 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.