General / 28 January 2022

Creating nuke nodes using Python


  • These are just some python notes I have taken doing visual effect as a compositor and decided put it up here


Creating a Grade node

Note: This is capital sensitive.

In the script editor of nuke type:


Option 1:

This will create a node and won't be connected to anything and will be placed randomly in the node graph and will not be selected.

nuke.nodes.Grade()

Option 2:

This way if you had a previously selected node it will create it right under neath and automatically connected to it and stays selected.

nuke.createNode("Grade")



To find out the Class of the node (node name):

To find out what the node is called, you want to make you find out the class. There is a few ways to do that.
You can either create the node and press " i " with that node is selected. A pop up menu will appear called nukescripts.getallnodeinfo() for "node".
On the second line of the pop up window it will say Class="class"


Example below: Class=Grade


This is useful as some nodes are not obvious example the exposure node the class is class=EXPTool
Another example is the merge node class=Merge2

You might be wondering why Merge2 and not Merge or Merge1?
Well if you type Merge1 when trying to create the node it would create the old merge node which the Foundry has left in but looks different then the latest version. Same thing applies to another node like VectorBlur.


Another way to do this is by selected the current node and typing 

#prints the class of selected node

print(nuke.selectedNode().Class())



#prints a list of all knobs that comes with selected node

print(nuke.selectedNode())



Creating a Node with a knob a certain set value:

what about if you want to make a node with knobs already set to a certain value?

nuke.nodes.Grade(white=1.5, whitepoint=0.5, gamma=0.8, channels='alpha')


This will create a grade node with:

gain (white) set to 1.5
whitepoint set to 0.5
gamma set to 0.8
channels set to alpha

We can take this further and create a variable

Example 1:

n = nuke.createNode('Grade')
n['white'].setValue(2)


This is basically saying "for the variable 'n' that now represents the Grade node, for it's white knob parameter set it to 2"
This is very useful in python as you can call the variable back at any given moment.

Example 2:

n = nuke.createNode('camera')
n['translate'].setValue([3,10,2])
n['display']setValue(3)


This will create a camera and set the translate x =3 , y =10 , z = 2 and the display to solid + wireframe