Nuke Knowledge Base

Nuke stuff I need the interwebs to remember for me.

Python

Set Custom Attributes on All New Nodes with Python

Especially when sharing scripts between artists, keeping tabs on who did what becomes a necessity. Labelling all newly created nodes with the users name, for example, might be a good idea. You can do that with a simple Python script in the script editor (or, if your pipeline is more advanced, put it in the menu.py and have it read out the logged in username or somesuch).

 

, ,

Set Roto Shape Attributes

You can access the attributes of shapes with Python script, for example to set a random opacity value per shape in a given roto node.

There’s more in-depth information on the Foundry forums:
http://community.thefoundry.co.uk/discussion/topic.aspx?f=190&t=103073
http://community.thefoundry.co.uk/discussion/topic.aspx?f=190&t=102867
http://community.thefoundry.co.uk/discussion/topic.aspx?f=190&t=102009

Set Expression via Python

To set an expression e.g. on a Dropdown-Menu, you’ll have to use Python instead of being able to drag’n’drop one knob to the other.

In case you would like to switch the antialiasing inside a Scanline Renderer to “high” when rendering on the farm, but keep working in the GUI with “none”, you could use a line like this:

Of Course you can use this for every kind of knob. Quite useful to link transformation and rotation order in 3d space, too.

Copying rendered files to a different folder via python

If you do some versioning on a shot, and want to keep those files in your version-folders, but also want to have a folder that always contains the latest renders, you can do this with python, and don’t have to add a second Write-node in your script.

Just add the following in the after each frame field in your Write-Node.

What this does is the following:

It thinks you render everything in your e.g. “…/output/001/…” – folder.
Then it splits the path and exchanges the 001 by “VLATEST”. If this folder doesn’t exist, it creates the folder.
Then it copies everything over via shutil.copy2().

This script assumes that you don’t have versioning on the filename at the moment. If you want to edit this, you have to adjust your destFile.

 

, , , , ,

Create render folders if they do not exist

To prevent your write nodes throwing “no such file or directory” errors, paste this bit of code into the python – before render section of the write:

 

Copy files on os level via python

This script copies the file of a Read node to a specific folder.

 

Disable knobs on a certain node with python

To do this for all knobs, just put it in a loop:

 

Execute writenode via python

 

Set keyframes in knobs with python

This example sets a knob to a defined value  in all frames .
nuke.Root()[‘first_frame’].getValue() returns float whyever…
So thats the reason i put it in “int()”

 

Create knobs with python

Syntax to create knobs (in this example a text-knob):

And here a short list of the most-needed knobs:

 

Previous Posts