Adding Layers and Channels in Nuke
If you need to create new layers in Nuke via Python, here’s the proper syntax:
nuke.tcl("add_layer", "newLayer newLayer.red newLayer.green newLayer.blue")
That was a bit hard to find in the docs as well as online and there’s some weird behavior (at least in Nuke 8) when this is called in a script vs typing it into the scripting console.
For example, the tcl input (“x” hotkey) requires you to enter the command as “add_layer {myLayer red green blue}” and it reminds you of the curly braces syntax in case you do it incorrectly. The .tcl method in Python, however, mustn’t contain curly braces.
Moreover, nuke.tcl requires you to spell out the rgb channels in dot format. If you just use “red green blue” Nuke will create a layer called “other” for some weird reason and probably crash sooner or later. It only does this in Python scripts though. Not in the scripting console.
You might have noticed that I’m calling a TCL command via Python. There’s also a native way: nuke.Layer(). Just like its tcl counterpart it requires you to spell out the channel names – even if the official docs say otherwise:
nuke.Layer("newLayer", ["newLayer.red", "newLayer.green", "newLayer.blue"])
Tags: Nuke