07.Splitting EXR Layers Using Dots and Shuffle Nodes in Nuke with Python

In this tutorial, we’ll go through how to split layers from an EXR file using a Python script in Nuke. This script automates the creation of Dot and Shuffle nodes to efficiently separate layers from a selected EXR file, arranging them neatly for further compositing.

Step 1: Select the EXR Node

The first step in the script is to select the node containing the EXR file. This is done using the nuke.selectedNode() function. It captures the node you have selected in your node graph.

				
					node = nuke.selectedNode()

				
			

Step 2: Retrieve EXR Layers

EXR files can contain multiple layers, such as RGB, Depth, and others. To get all the available layers in the selected node, we use nuke.layers(node).

				
					layers = nuke.layers(node)

				
			

This function returns a list of all the layers within the EXR file, allowing us to create separate nodes for each one.

Step 3: Get Node Position

Next, we need the x and y coordinates of the selected node to position the new nodes in a tidy manner. This is done with:

				
					x_pos = node['xpos'].getValue()
y_pos = node['ypos'].getValue()

				
			

These values allow us to determine the exact placement of new Dot and Shuffle nodes.

Step 4: Create a Master Dot Node

We create a master Dot node, which acts as the starting point for connecting to the selected EXR node.

				
					master_dot = nuke.nodes.Dot()
master_dot.setInput(0, node)
master_dot['xpos'].setValue(x_pos + 35)
master_dot['ypos'].setValue(y_pos + 300)

				
			

This positions the Dot node 35 units to the right and 300 units below the EXR node.

Step 5: Loop Through Layers and Create Nodes

Now, we loop through each layer in the EXR file. For every layer, we:

  • Create a Dot node connected to the previous Dot.
  • Create a Shuffle node to extract the specific layer.
				
					prev_dot = master_dot

for i, layer in enumerate(layers):
    dot_a = nuke.nodes.Dot()
    dot_a.setInput(0, prev_dot)
    dot_a['xpos'].setValue(prev_dot['xpos'].getValue() + 200)
    dot_a['ypos'].setValue(prev_dot['ypos'].getValue())
    prev_dot = dot_a

    sfl_a = nuke.nodes.Shuffle()
    sfl_a.setInput(0, prev_dot)
    sfl_a['in'].setValue(layer)
    sfl_a['label'].setValue('[value in]')
    sfl_a['xpos'].setValue(prev_dot['xpos'].getValue() - 35)
    sfl_a['ypos'].setValue(prev_dot['ypos'].getValue() + 200)
    prev_dot = dot_a

				
			
  • Dot node: For each iteration, a new Dot node is created and connected to the previous one.
  • Shuffle node: The Shuffle node extracts the current layer from the EXR, and the in knob is set to the layer’s name. This node is labeled with the layer name for easy identification.

The nodes are spaced 200 units apart horizontally for clarity.

Step 6: Result

After running this script, you will see a series of Dot and Shuffle nodes neatly arranged in your node graph. Each Shuffle node will have one of the EXR layers connected, allowing you to work with them individually.

Full Script

				
					node = nuke.selectedNode()
layers = nuke.layers(node)

x_pos = node['xpos'].getValue()
y_pos = node['ypos'].getValue()

master_dot = nuke.nodes.Dot()
master_dot.setInput(0, node)
master_dot['xpos'].setValue(x_pos + 35)
master_dot['ypos'].setValue(y_pos + 300)

prev_dot = master_dot

for i, layer in enumerate(layers):
    dot_a = nuke.nodes.Dot()
    dot_a.setInput(0, prev_dot)
    dot_a['xpos'].setValue(prev_dot['xpos'].getValue() + 200)
    dot_a['ypos'].setValue(prev_dot['ypos'].getValue())
    prev_dot = dot_a

    sfl_a = nuke.nodes.Shuffle()
    sfl_a.setInput(0, prev_dot)
    sfl_a['in'].setValue(layer)
    sfl_a['label'].setValue('[value in]')
    sfl_a['xpos'].setValue(prev_dot['xpos'].getValue() - 35)
    sfl_a['ypos'].setValue(prev_dot['ypos'].getValue() + 200)
    prev_dot = dot_a