Scripting for Artists in Nuke (Part1)


Hello ladies and Gentlemen
and welcome to my introduction series of Scripting for Artists My name is Alexander Richter and I want to give you a quick introduction
into scripting in Nuke So what do we have today for you The first Thing would be scripting languages which you can use in Nuke Next would be Node Expressions then I will show you the Script Editor and some valuable examples inside Nuke and last but not least we will have a look into how to use
external script files Let’s start right away with languages Nuke provide for you to script in. The first one would be
the scripting language Python which is best used for Generalist because you can use it across most DCC packages
in VFX and Animation starting from Nuke, to Maya,
Houdini, Katana and so on It provides you with mostly all Nuke functions to manipulate it for your needs. You can say it’s the main language in Nuke you can also say it’s the main language
across all the Foundry Packages which is a really great thing. The Next One would be
TCL which Is an acronym for
“tool command language” and it’s best used for expert node user because it allows you to manipulate
node expressions and node knobs. You will see TCL in a variety of software not just in the VFX and Animation for example in Microsoft Excel
you’ll stumble upon that So let’s compare the code of both languages here We want to get the project name In terms of Python we need first
to import the Nuke API we do an
“import nuke” and then we say Nuke
we want to access the root Then we want to have the knob name and we want to have the value In Terms of TCL we will use square brackets [] and we don’t have to use any Import since it’s already part of Nuke so we use square brackets
say we want to have the value and then again
root.name So let’s dive in into Nuke
and have a look. We open up a text node
and go into the Message and let’s have this example written in We use square brackets [value root.name] As you can see in the Viewer we get the current path of this Nuke file of the scene It’s easy as that so now we use this small expression from TCL to get the path from the current scene It’s easy as that so The first question is:
How do i know which values I can access? One way would definitely be:
Just Google it Search for:
“How to access the path name” as an example but the easiest way is just to hover over the knobs
let’s have a look so Let’s see:
Go into edit/project settings so we did access the root and set the name so if you would hover over this value You will get the tooltip “name” if you would hover for example over
the fps-knob You will get the tooltip fps Let’s try it out! Go back to the texts and let’s replace
“root.name” with “root.fps” As you can see we have the FPS down there This is the easiest way:
Just go to the knob you want to have access to Hover over the knob and then you get in bold letters the name of the valuable you want to access so how do we access for example
other nodes because this is one of the most important things For example I have here a write node
and I filled the file value with path Let’s hover over the file knob and it’s called “file”
easy as that so let’s go back into text and then write again
“value” and then we start with the name of the node so it’s “write1” and then dot and then the name of the knob which is in our case
“file” and as you can see
we accessed here the file value of the write node “I:/Alex/img.png” and here also “Alex.png” So easy as that
[don’t know why I repeat it :D] and with this technique you can access all the nodes in your scene just type in for example in TCL
the value then your name of the node
and then the name of the knob so okay cool Let’s do an expression here We go into the write node and for example let’s change the frame range
the starting frame range we do a right click on that
and do an “Add Expression” Here we get this expression window
and at the top we have the expression edit and at the bottom the results So here on the right hand side we have a button for multiple line which we should click
it’s better Here we can decide between doing an expressions in Python or normal expressions in TCL here we stay at TCL at the moment What could be a good thing to have here For example we want to start our frame range in our write node with the same one as the project setting so let’s have a look Go into “project settings”
and here’s the frame range Let’s have a look how it’s called So if we hover over that it’s called “first_ frame” and we are in the root so let’s write it down [value root.first_frame] and as you can see:
The result is 42 the same one as the start Project so let’s say
That’s fine
That’s okay So let’s go back into the write node
and as you can see the frame range now starts at “42” and will always be connected to the frame range of the project setting as its starting point How would we do the same thing in Python? For that matter we need to change to “Py” Of course now this value is not fitting We type in “nuke”
because we want to access the Nuke API and then again “nuke.root()” in Python ways and then we want to access the knob So the knob “first_frame” We want to access the value so “value” and as you can see we wrote mostly the same lines with some additions here and like Python specifics But the result is the same one
It’s “42” so this is the way to switch between
Python and TCL depends on what you know,
what you want to do if you’re more of a Python user
it’s easier for you to have it the Python way here A 3. way is:
sometimes you need to use a TCL command But just know the command in Python so what you can do:
You can write a TCL command with Python inside An Example would be: If you go into the text message
and here you can try for example You want to do something with Python so we want to print out the name Let’s print it out so here We write down the value of the name in Python but the end result is just the letters we wrote it doesn’t accept Python at all
because it waits for a TCL expression what we can do Is We can’t put It in in square brackets Let’s do that and then instead of value we write down: Python Now it accepts the next command as Python and uses the result of that to translate it into TCL and as you can see We get the current path of the Scene so this is like the easier way
because you can build in complete Python Commands and have it the Python way but to wrap around TCL and use it in a way that’s fitting for your needs If you do an expressions
you can always decide if you want to use the TCL approach especially if you just want to learn how to do expressions
maybe it’s a good way or if you’re more of a Python user
and also doing scripting it’s sometimes easier to do a Python approach and use Python results and values for that so it’s up to you and this is like the basic way of using Expressions In the next video:
I will show you how to do to use the Script Editor
with some examples and how to use external files and I will see you in the next video Goodbye [Subscribe for more]

Leave a Reply

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