In this tutorial I’m going to show you how to use a switch and pre render python script to drive multiple writes from the same script in Nuke.
The challenge I had was to produce multiple colour options for the same script and render them out through Deadline.
I simply couldn’t create a script for each colour option as the final results had to be identical (apart from the colour), and I was constantly updating the master script so I used expression switches to change the part of the of the comp that affected the diffuse layer.
A switch that goes between the constant colours is where the first important step happens, but instead of moving the slider in the switch, I created a NoOp node with a dropdown menu (right click, manage user knobs). This had nice logical names relative to what was getting piped in, the switchorder starting at 0 and going up. In the example case 0 is Red, 1 is Yellow, 2 is White, 3 is Grey and so on.
Now to get this to drive the switch node, an expression needs to be added to the slider input on the switch node.
Great, so we change the colour drop down and the script changes to whatever colour we select. So how do get each one of the colour options to write out to a separate folder at the same time?
The concept is surprisingly simple. Before each render node is executed, a python script is triggered that changes the switch to our desired colour via the dropdown menu we created.
To do this, create a write node for each colour version (make sure the write image sequence names are unique to each node), to go to the python tab and enter the following code in the ‘before render’ input:
n = nuke.toNode('Colour_Switch')
k = n.knob('colours')
It’s that simple – basically before the write node is executed, Nuke looks for the node ‘Colour_Switch’, goes to the controller knob ‘colours’ and changes it to your selection.
Though ‘before each frame’ would seem to make more sense when rendering via Deadline over a renderfarm, it was ‘before render’ that worked.
Once the script is set up it was very easy to make global changes the common elements of the comp then send them to render, knowing that Nuke and Deadline would happily spit them all out into their rightful destinations.
The final comp incorporated multiple switch changes at render time, you can use as many as you like!