Skip to main content
Tutorial

Nuke TCL Snippets

Some usefull TCL Snippets for nuke…

Getting a knob’s value of a specific node:

[value Read1.first]

First frame of current read/write:

[value this.first_frame]

Getting a knob’s value of current node:

[value this.size]

Return label value of the input node:

[value this.input0.label]

Name of the input node:

[value this.input.name]

Name of the node before the group (Outside):

[value this.parent.input.name]

Return 1 if the node is on error otherwise 0:

[value error]

Get the bounding Box from the input of the node:

[value input.bbox.x]#left boundary
[value input.bbox.r]#right boundary

Get the format from the input of the node:

[value input.format.r]#width
[value input.format.t]#height

Get the x position of the point #3 of the Bezier1 of the Roto1 node:

[value Roto1.curves.Bezier1.curve_points.3.main.x]

Return sample pixel value of the node Add1 reading in the red at position of knob Center:

[sample Add1 Red Center.x Center.y]

Get the value of the channel of a node, at a specific pixelcoordinates (e.g.: 10,10):

[sample [node input] red 10 10]

Set Values:

Setting a knob’s value of a specific node:

[knob Read1.first 10]

Setting a variable, without returning that (useful in a textnode):

[set seq [value Read1.file]; return]

Path Manipulation:

Relative to script location file path:

[file dirname [value root.name]]/example.jpg

Filepath without extension:

[file rootname [value [topnode].file]]

Filename only:

[basename [value [topnode].file ]]

Filename only without extension:

[basename [file rootname [value [topnode].file]]]

Splits the uppermost node’s (probably a readnode) filepath by slashes and then joins together until a certain point, giving a directory few levels upper than the currrent path). “File split” does the splitting, making a list of directory names, “lrange … 0 7 “selects a range from the list, from the beginning to the 7. item, and “join … / ” joins by forward slashes (which I use always in paths):

[join [lrange [file split [value [topnode].file]] 0 7] /]

This one can be used in a writenode fileknob to quickly convert the topmost readnode’s path to another format(tga). Similar to the previous, but splits path by “.” (different than previous file split), and gets the range from the beginning to 2 before the end, this way cutting off the extension and the counter (framecounter must have preceeded by a “.” )
(I use similar to make the comps writenode have the output path automatically getting from path of the nukescene ):

[join [lrange [split [value [topnode].file] .] 0 end-2] .].%04d.tga

Condition:

Example of “IF” in an expression:

[if {condition} {expr1} else {expr2}]
#for example:
[if {[value Switch1.which]==1} {return "aaa"} {return "bbb"}]

String substitution and Compare:

Replace string in current node file knob with regex (string “proj” to “projects” in all occurences):

[regsub -all "proj" [value [node this].file] "projects"]

String map (replace multiple stringpairs)(this returns: xxffffxxyy):

[string map {"aa" "xx" "bb" "yy"} "aaffffaabb" ]

Compare values:

[string equal [value Text1.message] "bla"]

Regexp matching:

[regexp -inline "_v\[0-9]{3}" [value Read2.file]]