TCL/Python Snippets

TCL/Python Snippets

Get input node name:

[python nuke.thisNode().input(0).name()]
[python nuke.thisNode().input(1).name()]

Set a variable in expression with TCL:


To use this variable later needs to type it as:


Get the last letter/section from node name, separated by “_”:


From the above, can be modified to acquire file extension


TCL String Operation that returns the 5th character from top input node name:

[string index [value [topnode this.input0].name] 5]

Use TCL string operation to converts to uppercase or lowercase:

[string tolower [value]]

Check if anything is plugged in to an input:

[exists this.input0]]
if nuke.thisNode().input(0)

Check input1 and check if anything is plugged in:

[value [topnode this.input0].name]
[exists parent.[string tolower [value [topnode this.input1].name]]]

This handy getting filename from topmost read I grabbed from Nukepedia

[lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]
[file dirname [knob [topnode].file]]/[lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]_conv.%04d.exr

Get nuke script base name without file extension

[lindex [split [file rootname [python nuke.root().knob('name').value()]] /] end]

Read metadata with TCL

[metadata input/filename]

Using expressions in Text node (needs to square bracket the whole thing):

[expression frame==1?1:0]

Get Bezier1’s point 0 (which is first point) position in Roto1 node :

[value Roto1.curves.Bezier1.curve_points.0.main]

Set expression with python found here, especially useful when setting to a dropdown menu which is usually not accessible

nuke.selectedNode()['antialiasing'].setExpression('$gui? 0:3')

List of all nodes but exclude selected ones:

n = nuke.allNodes()
for i in nuke.selectedNodes()
return n

Replace frame paddings (%04d) and extension with .mov

import re
v = nuke.toNode('Read1')['file'].value()
print re.sub(r'%.*d.exr', 'mov', v)

Search for frame paddings

f = nukescripts.replaceHashes(nuke.filename(n))
padd ='%.*d', f)

Leave a Reply

Your email address will not be published. Required fields are marked *