Nuke Knowledge Base

Nuke stuff I need the interwebs to remember for me.

Code

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.

Remapping values with the lerp() function

Someone on here (*cough*) went to great lengths to create a ValueMapper node a few years ago. Turns out, you can do the same thing much easier with the lerp() function. Like this:

Yeah, I know. Where was this function all these years?

Linearly interpolate animation curves with the lerp() function

Using random or noise functions to create movement like camera shakes can become annoying because it’s not always easy (or feasible) to control what’s going on between key frames. In that case you can “posterize” the result using the lerp() function like this:

with yourFunction referencing your original random curve and step being the interval in frames in which you want to sample that curve (so 5 would sample every 5th key frame, .2 would sample 5 times in-between key frames etc…).

Dealing with Inf or -Inf pixels

Inf pixels are a pain, because the empty areas of a render could be inf as well. So sampling the z with an expression node and using the value of an adjacent pixel for each of them will mess up your edges. If possible, try sampling the surrounding area instead. This will leave the edges intact but deal with the odd erroneous pixel.

 

Dealing with NaN pixels

When there are NaN pixels in your render you can either use the value of an adjacent pixel or the average of all adjacent pixels to fix it. The latter will probably give better results, but won’t work when there’s another NaN pixel next to the first one. In an expression node, type:

or

 

Mirroring animation timing using tcl

To mirror your animation curves, you can use some simple expressions. Let’s say you animated an object from frame 0-50, and now you want to mirror it to frame 51-100.

Just write the following in your specific knob:

This uses the command:

which will hold the animation on frame x. So what the above example does, it checks if the current frame is 50 or above. If this is true, it frameholds 50-(frame-50), which at frame 52 for example is …

So on frame 52, it frameholds frame 48. If the frame is under 50, is just gives you your current animated value.

This is pretty useful for creating walk-arounds or anything symmetrical, when you’re too lazy to animate everything. :-)

, , , ,

Restrict number of decimals when working with float and tcl

Say, you need to animate a number and want one decimal. You link a text node to a floating point slider to get the job done, however, it will output a never-ending string of digits that nobody really cares about. You can format this, however. Have no fear.

, , , , ,

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.

 

, , , , ,

Previous Posts