2
$\begingroup$

I have LOTS of View Layers (generated in Python), and I only want to render and composite several of them at once.

When I checked "Render Single Layer" in View Layer options, only the active one in the UI would be rendered.

When I unchecked "Render Single Layer", all of them are rendered, including those I'm not using in compositor. Even I have only one Render Layers node and one Composite node in the compositor, when I press F12 Blender still renders every single view layer.

Is it possible to only render the layers I'm using in the compositor? Or it can only be achieved by more scripting?

$\endgroup$

2 Answers 2

3
$\begingroup$

Set ViewLayer.use for all view layers based on render layer nodes

Iterate through the nodes, get the Render Layer nodes used in comp, read their RLayers.layer property and compare against Scene.view_layers. If part of the list, set each ViewLayer.use property to True, else set it to False:

import bpy

C = bpy.context

# List of render layer nodes
rl_comp = []
for node in C.scene.node_tree.nodes:
    if node.type == 'R_LAYERS':
        rl_comp.append(node)

# Set of view_layer_names used in the compositor
view_layer_names = set()
for vl in C.scene.view_layers:
    if vl.name in set([l.layer for l in rl_comp]):
        view_layer_names.add(vl.name)

# Set use property
for vl in C.scene.view_layers:
    if vl.name in view_layer_names:
        vl.use = True
    else:
        vl.use = False
$\endgroup$
5
$\begingroup$

If you have several layers, every layer has an "Use for Rendering" option. Tick this on all the layers you want and untick all you do not need. That's it.

enter image description here

The python property is ViewLayer.use, which you can access for each layer per data-block: bpy.data.scenes["Scene"].view_layers["LayerName"].use or per scene in context: bpy.context.scene.view_layers["LayerName"].use.

$\endgroup$
3
  • 1
    $\begingroup$ Hi :). Thanks for also including the script. I added an image of the UI, but feel free to remove it (it's your post after all). $\endgroup$ Mar 31, 2020 at 11:06
  • 1
    $\begingroup$ No, no need to remove it, it's a good Addition, thx J.M. $\endgroup$ Mar 31, 2020 at 12:41
  • $\begingroup$ Yeah, I was thinking if there is a faster way... but now that I think about it, perhaps the best way is just read compositor data from a script, find which view layers are here and set their use. $\endgroup$ Mar 31, 2020 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .