Render multiple outputs with python switches

Awesomeness

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:

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!

download script here

Posted in Tutorials and tagged with , , , , , , . RSS 2.0 feed.

4 Responses to Render multiple outputs with python switches

  1. Chris Glew Chris Glew says:

    If you have any questions just ask!

     
  2. Hi Chris
    Very cool and simple.
    I am working on a commercial project with a couple of different languages that will be in need of updates rather quickly.
    We should be able to extend this script to render all write nodes after each other and automatically switch input.
    Maybe in the ‘After render’ row it jumps to next render that will switch input.

    Best regards, Andreé K

     
  3. Chris Glew Chris Glew says:

    Hello Andreé,

    That would be really simple, you just need more switches. If you use Deadline it would be even easier as will render all your writes nodes in the order you set them (look at the Write node and set the number there in the order you need them).
    Does that help?

     
  4. I’m not sure why I would need more switches?
    When i use render-order it sticks to the command of the last writenode (in the render order)

    We don’t use Deadline in our workflow at the moment but it’s worth looking into.

    I found an other solution, I’m using your setup as demo.
    The downside of this setup is that it only works if all write Nodes are enabled.

    write_RED
    render order 1
    Before render: n = nuke.toNode(‘Colour_Switch’) k = n.knob(‘colours’) k.setValue(‘Red’)
    After each frame: n = nuke.toNode(‘Colour_Switch’) k = n.knob(‘colours’) k.setValue(‘Yellow’)

    write_YELLOW
    render order 2
    After each frame: n = nuke.toNode(‘Colour_Switch’) k = n.knob(‘colours’) k.setValue(‘White’)

    write_WHITE
    render order 3
    After each frame: n = nuke.toNode(‘Colour_Switch’) k = n.knob(‘colours’) k.setValue(‘Red’)

     

Leave a Reply