← All ideas
  • Published 18 Oct 2023

Output All Layers to Output Node in the Compositor

Hi! I think it would be great to have a button for a simple "Add all rendered layers to the Output node" with a creation of the sockets with the names.

I managed to do it with Python but a way to integrate that into Blender would probably speed everyone's workflows.

I'll post the script in the comments!

Screenshot (2736).png

100%

Development Status: Open

Upvote 5 Downvote 0
GabrielMoro
18 Oct 2023

6 Comments

GabrielMoro Author

The code I got (with an extra output for the JPEG Preview). It automatically creates the output node too (and I think it will override whatever you have currently - so use at your own risk?):

# Blender Python Script to Connect Enabled Render Passes to Multiple Output File Nodes
# Author: Gabriel Moro
# Version: 0.9

import bpy

# Ensure the compositor is activated
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree

# Clear default nodes
for node in tree.nodes:
    tree.nodes.remove(node)

# Create Render Layer and File Output nodes
render_layers_node = tree.nodes.new('CompositorNodeRLayers')
file_output_node = tree.nodes.new('CompositorNodeOutputFile')
file_output_node_jpeg = tree.nodes.new('CompositorNodeOutputFile')  # New JPEG output node

# Position nodes for visibility (optional)
render_layers_node.location = (0,0)
file_output_node.location = (400,0)
file_output_node_jpeg.location = (400, -200)  # Position of the new JPEG output node

# Reset File Output node layer slots and match them to enabled Render Layers
file_output_node.layer_slots.clear()

# Configure the new JPEG output node
file_output_node_jpeg.format.file_format = 'JPEG'

# Only keep the enabled outputs
for socket in render_layers_node.outputs:
    if socket.enabled:
        file_output_node.layer_slots.new(socket.name)

# Connect the sockets between the two nodes
for i, socket in enumerate([s for s in render_layers_node.outputs if s.enabled]):
    tree.links.new(file_output_node.inputs[i], socket)

# Connect the Image output to the new JPEG File Output node
image_socket = render_layers_node.outputs.get('Image')
if image_socket and image_socket.enabled:
    tree.links.new(file_output_node_jpeg.inputs[0], image_socket)

print("Enabled Render Passes and JPEG Image have been connected to the Output File Nodes.")

2
Lauloque

Please use triple ``` before and after your code to correctly format it as a fenced code block in Markdown .

1
GabrielMoro Author

Thanks for the tip, edited it! :)

1
thorn

Very useful script. Thanks for sharing!

1
GabrielMoro Author

Glad this will be of use. :) Thanks for the comment!

SpookyDoom

Very useful. Thanks for sharing. May I also push my related proposal for outputting each rendered Liew Layer directly without the Compositor to avoid RAM clogging?

Using too many View Layers will freeze your system and cause the render to fail. Devs might not yet know about it - I've been thrown out from Devtalk for being a feature request. Despita taht this is an actual stbility and usage limit that can be avoided.

blender.community/c/rightclickselect/19W3/