Expressions
Field of View calculations
This is a simple node for doing camera calculations.…
Automatic Write Node Versioning
if you run
nuke.root()['onScriptSave'].setValue("import re\n"+"rootVersion=re.search(\'[vV]\d+\',os.path.split(nuke.root().name())[1]).group()\n"+"for each in nuke.allNodes():\n"+" if each.Class() == \'Write\':\n" +" each[\'file\'].setValue(re.sub(\'[vV]\d+\',rootVersion,each[\'file\'].value()))")
your write nodes automatically increment their version number with the scripts version number when you save a new version of the script.
So if you have a script called MyScript_v01.nk and a write node with a file path that ends with MyRenderFile_v01.mov when you do File:Save…
Random Number Generator
A quick expression to generate numbers such as the gain value of a grade.
Either of these values will generate a value from 0 to 1.
random() or random(frame)
if you want to have the values from 0 to 2
2*random()
For generating from 1 to 2
1+random()
Detecting if a Node's Input has an Alpha Channel
The following expressions will check if the first input of a Node has a channel beginning with an "a". Obviously not 100% foolproof, but should get you started.
TCL Expression:
[string first ".a" [channels [input this 0]]]>-1
Python Expression:
[python "len(\[n for n in nuke.channels(nuke.thisNode().input(0)) if n.find(\".a\") != -1])>0"]
Enter the Matrix Knob
A new feature in Nuke 6.1 is the exposed matrix knob on all 3D nodes that allow a transform (such as ReadGeo, Axis, Camera etc). This contains all the transformation data for the node in a 4x4 matrix expressed as homogenous coordinates.…
Calling Python from an expression
You can easily call Python methods from within expressions, similar to calling Tcl expressions from Python via nuke.tcl()
To do this, you use the "python" Tcl method, for example:
[python nuke.thisNode().metadata().keys()]
While this is mostly straight-forward, there are a few things to be aware of..…
Dealing with NaN pixels
Here's an approach to dealing with the occasional NaN pixel that can for example crop up when outputting through the ScanlineRender node.…
Use of expressions to modify animation curves
Timing changes can be quite a headache in most compositing packages.…
Switching Nodes with $gui variable
Switch node states or node tree branches automatically between GUI and render use with the $gui variable
Have a slow operator or process in your script that you want to be off when working but on when you send it to the farm or render locally via the command line? Having trouble remembering to switch these functions on? Or do…
Smoothing Animation Curves
Smoothing an animation curve can be done through the animation curve's “Edit/Filter” option.
However, this will move the original keyframes which seems a little destructive and doesn't allow a nice fine tuning workflow (other than jumping up and down on the undo button and trying again with a different value).…
inrange - Check if a Frame is Within a Certain Range
Checking whether a certain frame or number is within a given range is often needed, and often resulting expressions are unnecessarily complex.…