Contact Support

Converting Expressions Between Scripting Languages

Depending on where you need to use an expression, you might find that you want to, for example, convert Nuke expressions to Tcl expressions or embed Python functions in a Nuke expression. The different languages are used in different parts of Nuke:

Python can be used in the Script Editor, in the Script Command (File > Comp Script Command) and in scripts run when Nuke starts (such as init.py and menu.py).For more information, see the Nuke Python documentation (Help > Documentation).

Tcl can be used in most string knobs (where text other than just numbers can be entered), in the Script Command dialog (File > Comp Script Command), to open some compatibility start up scripts (such as init.tcl and formats.tcl).

Nuke expressions can be used on the Add Expression dialog with most knobs in Nuke and expression entry field in the Expression node.

You can use the following functions to use different types of expressions together:

nuke.expression() to use a Nuke expression in Python code.

expression to use a Nuke expression in Tcl.

nuke.tcl() to run Tcl code in Python.

python to run Python code in Tcl.

[ ] (square brackets) to embed Tcl in a Nuke expression (or a string knob).

[python {...}] to embed Python in a Nuke expression.

Tip:  Note that putting braces ( { } ) around Python code when embedding it in Tcl may make the process a bit easier, because this prevents Tcl from performing its own evaluation of the Python code before passing it through to the Python interpreter. For example: [python {"hello " + "world"}]

Tip:  Note that the "python" Tcl command by default evaluates a single line of code and returns the result. Use the "-exec" option (for example, "python -exec") if you want to run multiple lines. Please refer to the Nuke Tcl Scripting documentation (Help > Documentation > TCL Scripting) for further information.