© 2014 by GATIMEDIA

EXPRESSIONS & TCL SNIPPETS

This is a collection of different Nuke expressions and TCL snippets. 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 ).

I also try to explain things as much as I can.

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: 

 

Linking Expressions

 

Cloning Nodes

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:

## Adding frame number as a value

 

x: frame OR t OR x

y: frame OR t OR x​

## To increase the amount of movement let's

multiply the value

 

x: random()*100

y: random()*100

##Slow down with dividing the frame number

x: sin (frame/10)*100

y: sin (frame/10)*100

 

 

x: sin(frame/10)*500

rotate: cos(frame/10)*100

## Movement in a circle clockwise

 

x: sin(frame/5)*100

y: cos(frame/5)*100

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

 

x: random()

y: random()

## Adding sinus to an equation. 

 

x: sin (frame)*100

y: sin (frame)*100

 

 

x: sin(frame/10)*500

rotate: sin(frame/10)*100

 

 

x: sin(frame/10)*500

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

## Movement in a circle counterclockwise

x: cos(frame/5)*100

y: sin(frame/5)*100

## Conditions ##

## 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 'asdf' is '0' return "hi" else "bye" - with TCL

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

## If knob 'asdf' is '0' return "hi" else "bye" - with Python

[python -eval {"hi" if nuke.thisParent()['asdf'].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 "" }]

## 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)

## 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.

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

![exists parent.input1]

## Formatting expressions ##

## Using the input values for Crop node.

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 value for Crop node. ( 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: input.root.t OR root.height OR root.h

## Using a root value in a Reformat node.

root.format

## Frame range expressions ##

## Using range values from input.

input.first_frame

input.last_frame

## Using range values from root.

root.first_frame

root.last_frame

## Displaying knob value on the node with TCL ##

size: [value size]

A channels: [value Achannels]

channels: [value Bchannels]

Range: [value range]

Range A: [value range.A]

Range B: [value ranfe.B]

Mode: [value mode]

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

Gain: [value white]

[value first_frame] - [value last_frame]

## Changing knob values in node with TCL ##

[knob Blur15.size 200]

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

[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.

[knob this.rotate frame]

When you set up value on a current node can call it with `this`.

## Setting keyframe value

[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.

## Showing input`s name with TCL and Python ##

## Showing single input

Input: [value this.input.name]

## Showing multiple inputs

 

Input B: [value this.input.input0.name]

Input A: [value this.input.input1.name]

## Showing all inputs with python

 

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

## Showing sampled pixel value with TCL ##

# In a ColorWheel I used:

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

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

# In a Grade I used:

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.

## Showing different values with TCL ##

## Showing channels

[channels this]

## Showing filename

[filename this]

## Showing part of filename

[lrange [split [file tail [knob [topnode].file]] _ ] 0 0 ]

Explanation: Separates filename at every `_` - the first number stands for the 

beginning of the filename the second is for how many parts to show.

## Changing node`s colour by knob value with TCL ##

## 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 }]]

## Showing all root info with TCL ##

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]

## TCL commands to show values on Read with Text ##

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

[metadata]

## Showing certain metadata ##

Input/timecode: [metadata input/timecode]

Input/ctime: [metadata input/ctime]

Input/filesize: [metadata input/filesize]

Input/filereader: [metadata input/filereader]

## Showing date in different ways​ ##

 

[clock format [clock seconds]]

 

[date]

## Showing frame number in different ways ##

Frame: [value frame]

Frame: [python {nuke.frame()}

## 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]

## 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]]

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

[metadata keys *time*]

## 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)

## Adding images to nodes with TCL ##

<img src= "Shuffle.png">

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

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

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

## Text editing on label with HTML ##

## Center ##

<center>Lorem Ipsum</center>

## Italic ##

<i>Lorem Ipsum</i>

## Strikethrough ##

<s>Lorem Ipsum</s>

## Changing font colour with Hex code ##

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

## Superscript ##

Lorem <sup>Ipsum</sup>

## Align text to the right 1 ##

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

## Strong ##

<strong>Lorem Ipsum</strong>

## Small ##

<small>Lorem Ipsum</small>

## Bold ##

<b>Lorem Ipsum</b>

## Underline ##

<u>Lorem Ipsum</u>

## Font size ##

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

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

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

## Subscript ##

Lorem <sub>Ipsum</sub>

## Align to the right 2 ##

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

## Big ##

<big>Lorem Ipsum</big>

## Emphasized ##

<em>Lorem Ipsum</em>

## Links I recommend ##

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!