This article explains how to use a Switch node in conjunction with a single Write node to output different results within a Nuke script.

The Switch node serves the purpose of alternating between various inputs. When used as an input to a Write node, it can allow the script to render multiple results by using frames to call individual inputs.

MORE INFORMATION

An expression can be used in the “which” knob of the Switch node that sorts the frames for each input available, as illustrated in the example below.

This script may be useful for outputting multiple results from a script to be rendered at one time. For example, let’s say that there are 3 images appearing too fast in a sequence. You can use this Switch node process to increase the number of frames for the images, thereby altering the speed of the sequence by adding more frames to slow it down.

Example:

Rendering 3 inputs with 10 frames each on a single Switch:

In the Node Graph, create a Switch node.

Add 3 Constant nodes.

Change the color values for each node as Red, Green, and Blue, as seen below.

Connect the Constant nodes to the inputs of the Switch node. These should now appear connected as (Red - 0, Green - 1, Blue - 2) respectively.

Double-click the Switch node to open the Properties Bin.

Right-click the “which” knob and selectAdd expression...

Add the following code to the Expression field and press OK to confirm: root.frame()%30/10

Add a Write node and connect it to the Switch node.

Open the Properties Bin of the Write node, and set the file path to render files in a specified directory.

Click Render and view the render prompt.

Set the frame range as 0-29, and click OK to begin rendering.

View the output folder and observe the images created.

With the above rendering, there should be an output of 3 colors with 10 frames each from a single Write node, as seen in the following screenshot:

ADDITIONAL NOTES:

You can use this process for rendering multiple inputs at once, sorting frames by the expression in the “which” field of the Switch. From my example above, the expression of root.frames()%30/10 can be extended for however many inputs are accessible. You may also use the expression frame%30/10 to achieve the same results.

If you only want 1 frame per render, than you would use an expression such as: root.frames()%3 per 3 inputs. Additionally, if you wanted 3 frames per render, than the expression root.frames()%9/3 could be used.

NOTE: The expression %3 would change with each input to be relative to the maximum amount of inputs available. (i.e %4 using 4 inputs, %5 for 5, etc.) Please view the Further Reading section below for more information regarding the expression with the percent symbol used as modulus math.