Nuke Scripting

For scripting go click the button on the top left of the nuke pane. Go to windows-> Script Editor. In the script editor you can write and execute scripts. At the top bar of the script editor are buttons for saving and importing (or importing and executing) scripts. nuke python documentation =Put latest executed script in script editor= control + [ =Models= Nuke provides models in python to perform certain operations.

=Duplicate selected nodes= nukescripts.node_copypaste Where nukescripts is the model node_copypaste the function and the brackets indicate that it's a function.

=Selection=

Store selected Node
variable = nuke.selectedNode

=Creating Nodes= After a node is created it's always selected. So when creating multiple nodes there always connected and aligned vertically by default.

Create node in a variable
When creating a node in a variable you give yourself the opportunity to call the node later in the script to do other operations on it. namevariable = nuke.createNode('classofthenode') Example frameholdcam = nuke.createNode('FrameHold')

=Node Connection=

setInput
This function will set the input of a node. a.setInput(b,c) a = is the node name. This can be a hard coded node name or a variable storing a node name. b = the input number, for example when a node only has one input this has to be 0. Or when you want to connect to the mask input for a grade for example this had to be 1. c = Where to connect the node to. If it shouldn't connect to anything you can put "None" in this field. Example Project3D1.setInput(0,FrameHold3)

=Comment= Piece of script that doesn't do anything and is just for clarification of the code. A comment can be made by starting the line with a # symbol.

=Changing Knobs=

Get the name of a knob
Hover your mouse over the knob you want to know the name of.

Set Value on a Knob
a.knob('b').setValue(c) a is the node name. This can be a hard coded node name or a variable storing a node name. b is the name of the knob you want to target. c is the value that the knob has to take. When it's a knob with a drop-down list it will pick according to the list number so 0 will be the first thing in the list and 1 the second etcetera. Example: FrameHold1.knob('first_frame').setValue(10)

for in loop
This is a python script to loop trough a piece of code until it's executed for everything within the loop. This can be used to change a knob on a lot of nodes at once: for i in nuke.selectedNodes: i.knob('Choose a knob here').setValue(Choose a value here) To change all the bounding boxes of multiple merges to B for example: for i in nuke.selectedNodes: i.knob('bbox').setValue(3)

Set expression on a knob
a.knob('b').setExpression(c) a is the node name. This can be a hard coded node name or a variable storing a node name. b is the name of the knob you want to target. c is the Expression that the knob has to take. Example frameholdcam.knob('first_frame').setExpression(frameholdimg.knob('name').value+'.knob.first_frame') frameholdimg.knob('name').value is the way of targetting a soft coded node from within the expression editor.

Change the color of a node
NodeName.knob('tile_color').setValue(colorcode) for the color of the locator use NodeName.knob('gl_color').setValue(colorcode)

Get the colorcode of a node
You can use the get value function to print the color code print nuke.selectedNode.knob('nameOfTheKnob').getValue Example print nuke.selectedNode.knob('tile_color').getValue

Change the label of a node
nodeName.knob('label').setValue('label text')

=Timeline=

Current Frame
To call the current frame: nuke.frame