top of page

EXPRESSIONS & TCL Tips

This is a collection of different Expression and TCL snippets ( and some python and HTML).

I picked these from various sites, among from pages of talented TDs websites ( of which I provide a list of a few at the bottom of this page ). As it's said it is not a site explaining the Expression node, which if you're interested in I recommend you the Expressions 101 by Matt Estela and Pedro Andrade.

Feel free to use and share!

So what is Expression in Nuke anyway?

- Basically, programmatic commands that you can apply as parameters in Nuke.

 

What is TCL?

- Tcl or Tool Command Language (pronounced as `Tickle`) is a high-level, general-purpose, dynamic programming language. ( for more info here`s a Wikipedia link )

 

How to apply them?

- There are multiple ways, depends on what kind of expressions you want to use and for what purpose.

 

I recommend a few useful links from the Foundry`s website before you start to experiment with the snippets I collected: 

Expressions

Linking Expressions

Mathematical functions

Nukepedia TCL library

TCL Documentation

Expressions on Transform

Expressions on Transform

So let`s start applying some expressions!

I use a `Transform` node to show the result of the first snippets but the values it produces are the same in any node where you can add expression as the knob`s value.

And the first one should look like this:

001.jpg

( You can double click on the videos to make full screen )

## Adding frame number as a value

 

x: frame OR t OR x

y: frame OR t OR x​

## Adding random number as a value ( the 'random()' generates numbers between 0 and 1 )

 

x: random()

y: random()

## To increase the amount of movement let's

multiply the value

 

x: random()*100

y: random()*100

## Adding sinus to an equation. 

 

x: sin (frame)*100

y: sin (frame)*100

##Slow down with dividing the frame number

x: sin (frame/10)*100

y: sin (frame/10)*100

 

 

x: sin(frame/10)*500

rotate: sin(frame/10)*100

 

 

x: sin(frame/10)*500

rotate: cos(frame/10)*100

 

 

x: sin(frame/10)*500

rotate: cos(sin(frame/10))*100

## Movement in a circle clockwise

 

x: sin(frame/5)*100

y: cos(frame/5)*100

## Movement in a circle counterclockwise

x: cos(frame/5)*100

y: sin(frame/5)*100

Displaying knob value

Displaying knob value
002.jpg

size: [value size]

003.jpg

A channels: [value Achannels]

channels: [value Bchannels]

004.jpg

Range: [value range]

Range A: [value range.A]

Range B: [value range.B]

005.jpg

Mode: [value mode]

RGB: [value red], [value green], [value blue]

006.jpg

Gain: [value white]

007.jpg

[value first_frame] - [value last_frame]

Format expressions

Format expressions

## Using the input format values

x: input.format.x

y: input.format.y

r: input.format.r OR input.width OR input.w

t: input.format.t OR input.height OR input.h

## Using the input format in Reformat node. ( Only works if connected node has format information like Read node )

input.format

## Using the root values ( root values are the ones in the Project Settings which you see on the Properties if you press S on the Node Graph )

x: root.format.x

y: root.format.y

r: root.format.r OR root.width OR root.w

t: root.format.t OR root.height OR root.h

## Using a root value in a Reformat node.

root.format

## Using the bounding box values

x: bbox.x

y: bbox.y

r: bbox.r OR bbox.width

t: bbox.t OR bbox.height

Frame expressions

Frame expressions

## To return current frame value

frame OR t OR x

## Using range values from input.

input.first_frame

input.last_frame

## Using range values from root.

root.first_frame

root.last_frame

Useful Conditional expressions

Useful conditional exprssions

## If frame number is lower than 1010 value is 0 else 100.

frame < 1010 ? 0 : 100

## If 'Transform1' translate.x value is 100 the value is 500 else 0

[if {[value Transform1.translate.x]==100} {return "500"} {return "0"}]

## If frame number is 100 the value is 500 else 0

[if {[frame]==100} {return "500"} {return "0"}]

## If knob 'test' is '0' return "hi" else "bye" - with TCL

[if {[numvalue parent.test] == 0} {return "hi"} else {return "bye"}]

## If knob 'test' is '0' return "hi" else "bye" - with the python function.

[python -eval {"hi" if nuke.thisParent()['test'].array()[0] else "bye"}]

## If Text1 node's 'message knob has "Notes:" feature the note else leave empty.

[python -eval {nuke.toNode("Text1")["message"].value().split("Notes:")[1].split("\n")[0] if "Notes:" in nuke.toNode("Text1")["message"].value() else "" }]

Conditional expressions for 'disable' knob

## If frame number is greater than 1010 value is 1 ( = node is disabled )

frame > 1010

## Between frame 1010 and 1015 value is 1 ( = node is disabled )

inrange (frame, 1010, 1015)

## You can also add multiple ranges

( formula: inrange (frame, start, end, start, end, start, end) )

inrange (frame, 1010, 1015, 1025, 1035)

## Gui ( Graphic User Interface ) returns 1 ( = node is disabled ) when Nuke is running. It works well on heavy nodes when you run your render on a renderfarm.

$gui

## When the script is in use returns 1 else 12.

$gui ? 1 : 12

TIP: You can use $gui in a Switch node putting heavy nodes like Defocus on input 1 and Blur can be used while working on input 0.

For more about $gui click here.

## True if the name item exists. ( Useful for gizmos with mask input )

![exists parent.input1]

You can find more conditional TCL functions here.

Changing knob values

Chaging knob values
008.jpg

[knob Blur15.size 200]

After you call a knob function you need to define the node`s then the knob`s name before you give a new value to it. 

009.jpg

[knob Blur13.size Blur_CONTROL_2.size*3]

[knob Blur13.channels rgb]

[knob Blur13.mix .8]

You can also define multiple values from one node and can use expressions as value.

010.jpg

[knob rotate frame]

You can also add expression as a value like frame here that returns the

current frame number.

## Setting keyframe value with setkey

[setkey this.size 34 2]

If you want to set a keyframe in a different node use the node`s name instead of this.

After defining the knob the first number is the frame number the second is the value.

Displaying input's name

​Displaying input's name
011.jpg

## Showing single input

Input: [value input.name]

012.jpg

## Showing multiple inputs using input's 

 

Input B: [value input0.name]

Input A: [value input1.name]

013.jpg

## Showing all inputs with python

 

[python {"\n".join(["Input: %s" % node.name() for node in nuke.thisNode().dependencies()])}]

Displaying pixel value

Displaying pixel value
014.jpg

# In the ColorWheel

R: [sample [node ColorWheel5] red 1075 378]

G: [sample [node ColorWheel5] green 1075 378] B: [sample [node ColorWheel5] blue 1075 378]

# In the Grade:

R: [sample [node this] red 1075 378]

G: [sample [node this] green 1075 378]

B: [sample [node this] blue 1075 378]

A: [sample [node this] alpha 1075 378]

Here again, you can call a node by name or with this

After you define the channel the first number is from the X axis the second from the Y axis.

Formatting

Formatting
049.jpg

# Setting the number of decimals

Size: [format %.1f [value size]]

# Setting the number of characters

Filter: [format %.5s [value filter]]

You can find out more about the format function here.

Displaying different values

​Displaying different values
056.jpg

## Showing layers

layers: [layers this]

057.jpg

## Showing channels

Channels: [channels this]

058.jpg

## Showing node

Node: [node this]

059.jpg

## List of knobs

Knobs: [knobs this]

060.jpg

## List of values

Values: [values this]

All values: [values -a this]

Non-default values: [values -d this]

061.jpg

## Node info - same list of information that comes up when you select 

a node and press i or nukescripts.getallnodeinfo() with python.

Info: [show_info]

062.jpg

## Returns number of inputs

Inputs: [inputs this]

063.jpg

## Returns list of all plugins

Plugins: [plugins]

064.jpg

## Returns list of all formats

Formats: [formats]

065.jpg

## Returns the full name, when used in Group returns with name of Group

Full name: [full_name this]

066.jpg

## Dependent_nodes returns list of nodes that are connected via expression

Can use the lindex function to select item from the list.

Dependent node: [value [lindex [dependent_nodes this] 0].name]

067.jpg

## Dependencies returns list of nodes that are connected via inputs

Dependency: [value [lindex [dependencies this] 2].name]

068.jpg

## Returns filename when knob exist on node

[filename this]

Using variables

Using variables

## Setting a variable

[set var1 25]

In the example above with using 'set' you can add the first argument 'var1' that is the variable and then the value '25' that it stores.

## Calling the variable

$var1

With $ before the name of the variable you can add the stored value - 

In this case it is 25. You also don't need the square brackets '[ ]' here!

041.jpg
042.jpg

When assigning value you can sample a knob value too.

[set transX [value translate.x]]

$transX

044.jpg

When using the variable can also use the 'knob' function.

[set transX [value translate.x]]

[knob size $transX]

046.jpg

You can also apply mathematical functions on the numerical values.

Here is a list of them.

[set transX [value translate.x]]

sin($transX * 5)

043.jpg

When using a different node to sample for the variable it will

be connected with an expression line! (It is green by standard but you can

change in the Preferences)

[set shotName1 [file tail [value Read1.file]]]

shot1 :  $shotName1

047.jpg

You can also apply other functions on the stored strings.

Here are a few examples.

[set shotName1 [file tail [value Read1.file]]]

shot1 : [string tolower $shotName1]

shot1 : [lrange [split $shotName2 _] 0 1]

Changing node's colour

​Changing node's colour

## Changing node`s tile color with changing knob`s value.

[knob tile_color [value which]]

This one is for a Switch node that`s why it calls a`which` knob but you can use it with most knobs that generates numbers.

## Changing node`s tile color for 0 and 1.

[knob tile_color [ expr { [value which]? 814350335 : 4284416255 }]]

Displaying all root info

​Displaying all root info

Root info

 

name: [value root.name]

project directory: [value root.project_directory]

frame range: [value root.first_frame] - [value root.last_frame]

fps: [value root.fps]

format: [value root.format]

proxy mode: [value root.proxy_type]

proxy scale: [value root.proxy_scale]

read proxy files: [value root.proxySetting]

color management: [value root.colorManagement]

OCIO config: [value root.OCIO_config]

monitor: [value root.monitorLut]

8bit files: [value root.int8Lut]

16bit files: [value root.int16Lut]

log files: [value root.logLut]

float files: [value root.floatLut]

views: [value root.views]

Commands for Text node

​Commands for Text node
015.jpg

## Showing all metadata's name (value not included) ##

[metadata]

016.jpg

## Showing certain metadata ##

Input/timecode: [metadata input/timecode]

Input/ctime: [metadata input/ctime]

Input/filesize: [metadata input/filesize]

Input/filereader: [metadata input/filereader]

017.jpg

## Showing date in different ways​ ##

 

[clock format [clock seconds]]

 

[date]

019.jpg

## Showing frame number in different ways ##

Frame: [value frame]

Frame: [python {nuke.frame()}

020.jpg

## Getting value with Node`s name ##

Node name: [value Read15.name]

File name: [lrange [split [basename [value [topnode].file]] .] 0 0]

File: [value Read15.file]

Format: [value Read51.format]

Frame Range: [value Read15.origfirst] - [value Read15.origlast]

Colorspace: [value Read15.colorspace]

021.jpg

## Breaking down values ##

Root dir: [file dirname [knob [topnode].file]]

File name: [file tail [knob [topnode].file]]

Shot name: [lrange [split [file tail [knob [topnode].file]] _ ] 0 1 ]

File extension: [file extension [knob [topnode].file]]

022.jpg

## Show filtered metadata (value not included) ##

[metadata keys *time*]

018.jpg

## Time and Date in TCL ##

[date %%] a literal %

[date %a] weekday name (Sun..Sat)

[date %A] full weekday name (Sunday..Saturday)

[date %b] abbreviated month name (Jan..Dec)

[date %B] full month name (January..December)

[date %c] Unix style (Sat Nov 04 12:02:33 EST 1989)

[date %d] day (01..31)

[date %D] date (mm/dd/yy)

[date %e] day of month, blank padded ( 1..31)

[date %h] same as %b

[date %H] hour (00..23)

[date %I] hour (01..12)

[date %j] day of year (001..366)

[date %k] hour ( 0..23)

[date %l] hour ( 1..12)

[date %m] month (01..12)

[date %M] minute (00..59)

[date %p] AM or PM

[date %r] time, 12-hour (hh:mm:ss [AP]M)

[date %s] Unix seconds [date %S] second (00..60)

[date %T] time, 24-hour (hh:mm:ss)

[date %U] week number with Sunday as first day of week (00..53)

[date %V] week number with Monday as first day of week (01..53)

[date %W] week number with Monday as first day of week (00..53)

[date %w] day of week (0..6), Sunday = 0

[date %x] (mm/dd/yy)

[date %X] time, 24-hour (hh:mm:ss)

[date %y] year (00..99)

[date %Y] year (1970..)

[date %z] RFC-822 style numeric timezone (-0500)

[date %Z] time zone (e.g., EDT)

You can find more TCL functions that are useful in Text nodes HERE.

Display metadata

Display metadata
074.jpg

[metadata]

 Display all metadata keys

075.jpg

[python {"/n".join(nuke.thisNode(). metadata())}]

 Display all metadata keys with python

076.jpg

[metadata input/timecode]

 Display specific metadata's value

077.jpg

[python {nuke.thisNode(). metadata().get("input/timecode")}]

 Display specific metadata's value with python

078.jpg

[metadata keys *time]

 Display filtered metadata keys ( ones that end with "time" here )

079.jpg

[python -exec {

timeMetas = []

for i in nuke.thisNode().metadata():

    if i.endswith("time"):

        timeMetas.append(i)

timeMeta = ('\n '.join(timeMetas))

}] [python timeMeta]

 Display filtered metadata keys with python ( ones that end with "time" here )

080.jpg

[metadata keys]

 Display all metadata keys

081.jpg

[metadata values]

 Display all metadata keys with values

080.jpg

[metadata -s "\n " keys input/*]

 Display filtered metadata keys with custom separator ( ones that starts with "input/" here )

083.jpg

[metadata -v ": " values]

 Display metadata keys with values using custom separator

084.jpg

[metadata -v ": " values *time*]

 Display filtered metadata keys with values using custom separator

( ones that includes "time" here )

085.jpg

[metadata -n Read15 values]

 Display metadata keys with values from specific node

086.jpg

[metadata -n Read15 input/timecode]

 Display metadata value from specific node

Referencing Foundry page.

Adding images / emojis to nodes with html

Adding images / emojis to nodes with html

023.jpg

<img src= "Shuffle.png">

You can add the image of any default node icon by putting its name instead of the `Shuffle`​.

024.jpg
025.jpg

<img src= "D:/gatimedia_white_logo.png">

You can also add any image to a label, just copy the path between the quotation marks.

Even more fun is that you can use emojis in Nuke!

In this example I added the code to the Text knob

069.jpg

<p style="font-size:100px">&#129409;</p>

The code is from here where you can find a lot more codes for different emojis.
There is a site also for smiley emojis and for different skin tones

In this fomula you can adjust the size ( which is 100px here ),

and which emoji you want to display by changing the decimal code ( which is 129409 here ).

070.jpg

<p style="font-size:100px">&#129304;&#127999;</p>

For changing the skin tone you need to use two decimal codes - first for the type of emoji and the second one for the skin tone.

071.jpg

<p>I will display &#129409;</p>

Can also use the decimal code without setting the size and it will be the size of the text.

Make sure you define the paragraph before and after ( <p> - start, and </p> - end ),

otherwise it will only appear as a text.

072.jpg

You can also add emojis to the label but it might won't look as expected.

073.jpg

Also can use them as name of the user knobs.

Text editing with html

Text editing with html
026.jpg

## Center ##

<center>Lorem Ipsum</center>

028.jpg

## Italic ##

<i>Lorem Ipsum</i>

030.jpg

## Strikethrough ##

<s>Lorem Ipsum</s>

031.jpg

## Changing font colour with Hex code ##

<font color=#582b00>Lorem Ipsum</font>

035.jpg

## Superscript ##

Lorem <sup>Ipsum</sup>

036.jpg

## Align text to the right 1 ##

<p style="text-align:right">Lorem Ipsum</p>

037.jpg

## Strong ##

<strong>Lorem Ipsum</strong>

039.jpg

## Small ##

<small>Lorem Ipsum</small>

027.jpg

## Bold ##

<b>Lorem Ipsum</b>

029.jpg

## Underline ##

<u>Lorem Ipsum</u>

033.jpg

## Font size ##

<font size="5">Lorem Ipsum</font>

032.jpg

## Changing font colour with colour`s name ##

<font color=aqua>Lorem Ipsum</font>

034.jpg

## Subscript ##

Lorem <sub>Ipsum</sub>

036.jpg

## Align to the right 2 ##

<p align="right">Lorem Ipsum</p>

038.jpg

## Big ##

<big>Lorem Ipsum</big>

040.jpg

## Emphasized ##

<em>Lorem Ipsum</em>

051.jpg

## Headers ##

<h1>Lorem Ipsum</h1>

<h2>Lorem Ipsum</h2>

<h3>Lorem Ipsum</h3>

<h4>Lorem Ipsum</h4>

<h5>Lorem Ipsum</h5>

Lorem Ipsum

052.jpg

## Adding a link to a node using a Text knob ##

<a href="https://www.gatimedia.co.uk/">Visit my page!</a>

Environment variables

Environment variables
053.jpg

## Using python in the script editor to print all env variables ##

import os

for k,v in sorted(os.environ.items()):

    print (k,": ",v)

You can find out more about how to use python snippets HERE.

054.jpg

## Using TCL to print all env variables ##

[array get env]

## Search in the array

[array get env *NUKE*]

055.jpg

## Using TCL to print specific env variable ##

[getenv NUKE_TEMP_DIR]

Useful links

Useful links

If you want to dig deeper into the wonderful ( and often frustrating ) world of TCL commands in Nuke you should visit Nuke TCL Scripting Documentation.

Hope you will find it useful! 

bottom of page