some Nuke Python snippets

Seeing as I’ve found very little reference for the use of python in nuke on the web I thought I’d create this post and add to it with little code snippets.

If anyone has some cool snippets to share please feel free to leave them in a comment below.

disable “postage stamps” on only “Read” nodes

for a in nuke.allNodes():
   if a.Class()=='Read':
       a['postage_stamp'].setValue(0)

disable “postage stamps” on all nodes

for a in nuke.allNodes():
    try:
        a['postage_stamp'].setValue(0)
    except:
        pass

“unhide” all nodes’ inputs – useful when receiving a sneaky comp/lighting script

for a in nuke.allNodes():
    try:
        a['hide_input'].setValue(0)
    except:
        pass

change the “first” frame of all selected nodes that are “Read” nodes:
(example changes the first frame to 1018)

for a in nuke.selectedNodes():
    if a.Class() == 'Read':
        a['first'].setValue(1018)

print a selected nodes’ methods

import struct
node = nuke.selectedNode()
for a in node['lookup'].animations():
    print dir(a)

print inputs (dependencies) of a selected node:

for a in nuke.selectedNode().dependencies():
    print a.name()

print outputs (dependents) of a selected node:

for a in nuke.selectedNode().dependent():
    print a.name()

find all the TimeOffset nodes in a Group called “Group2″, and change the value of each offset based on it’s position in the array of found time offsets

tos = []
for a in nuke.toNode('Group2').nodes():
	if a.Class()=='TimeOffset':
		tos.append(a)
for b in tos:
	b['time_offset'].setValue(tos.index(b))

set the ‘bbox’ for any selected Merge, Keymix & Copy nodes to “B”

for a in nuke.selectedNodes():
	classTypes = ['Merge' , 'Keymix', 'Copy', ]
	for n in classTypes:
		if n in a.Class():
			for p in a['bbox'].values():
				if 'B' in p:
					a['bbox'].setValue(a['bbox'].values().index(p))

remove all animation from a selected nodes

for a in nuke.selectedNode().knobs():
	nuke.selectedNode()[a].clearAnimated()

add keyframes – animate a mix

for a in nuke.selectedNodes():
	a['mix'].setAnimated()
	a['mix'].setValueAt(1,nuke.frame())
	a['mix'].setValueAt(0,(nuke.frame() - 1))

half the colour value of all the Constant nodes in a script

for a in nuke.allNodes():
	if a.Class() == "Constant":
		a['color'].setValue(a['color'].value()[0] / 2 , 0)
		a['color'].setValue(a['color'].value()[1] / 2 , 1)
		a['color'].setValue(a['color'].value()[2] / 2 , 2)

find all the transform nodes in a script, and if their input is a Crop, set the ‘scale’ value to be twice it’s current value (also checks if the scale is a list/array or a float)

for a in nuke.allNodes():
	if a.Class() == "Transform":
		if a.input(0).Class() == "Crop":
			x = a['scale'].value()
			if type(x).__name__ == 'list':
				a['scale'].setValue(x[0] * 2 , 0)
				a['scale'].setValue(x[1] * 2 , 1)
			if type(x).__name__ == 'float':
				a['scale'].setValue(x*2)

set all the gain values of all ColorCorrect nodes to be twice their current value

for a in nuke.allNodes():
	if a.Class() == "ColorCorrect":
		a['gain'].setValue(a['gain'].value() * 2)

print files with ‘mov’ in filename

for a in nuke.allNodes():
	if 'Read' in a['name'].value():
		if 'mov' in a['file'].value():
			print a['file'].value()

change font size of all “write” nodes in script

for a in nuke.selectedNodes():
	if "Write" in a['name'].value():
		a['note_font_size'].setValue(60)

create 20 constants with incrementing colour values

def makeConstants(amount):
	for i in range(amount):
		a= nuke.nodes.Constant()
		color= float( float(i) / float(amount) )
		a['color'].setValue(color)
makeConstants(20)

change the name of all Text nodes to contents the text “message”

for a in nuke.allNodes():
    if a.Class()=='Text':
        a.setName(a['message'].value())

distributed rendering using Apple Qmaster 3 – success!!!

qmaster3logo


Thanks to a fair amount of googling and a few days on and off of testing I seem to have a working setup for doing distributed processing using Apple Qmaster – for Shake, Maya and Compressor.

Here is my effort at explaining what I did to get it working – big apologies, it’s poorly written. I’ll revisit this post soon.

some notes on our workflow

  • Our current workflow for dealing with files/assets evolves around a directory structure that breaks each project up into shot numbers and the various departments we have etc..
  • Our xserve is the centralised area for our assets and the QMaster render manager.
  • Each artist’s local machine has a directory somewhere that mimics the xServe’s project directory structure for working locally (to keep network traffic down over gigabit ethernet).
  • I set up $JOBS_LOCAL and $JOBS_SERVER env variables on each machine and the xserve – these variables point to the relevant local project directory on the artist’s mac and the project directory on the server.
  • I created a python script that does a find and replace of the 2 variables and writes our a new shake script renamed “*_SERVER.shk”, or “*_LOCAL.shk”
  • (See further down for setting up the ENV variables.)

    Centralised $NR_INCLUDE_PATH
    I setup an env variable for $NR_INCLUDE_PATH for all Shake machines and the xserve – to look at a sharepoint (the nreal folder) on the xServe and automatically mount it – so all the Shake machines would be using the same macros/plugins and settings. I setup a new user on the xserve “shake” that can only mount the nreal directory.

    After some googling around I found a way to automount volumes:

    OS X 10.5 (fstab)
    /etc/fstab – to automount sharepoint on xServe
    LINK: http://blogs.sun.com/lowbit/entry/easy_afp_autmount_on_os

    # ————————————————————————————-
    # Mount AFP share from xServe via AFP
    # ————————————————————————————-
    ourserver.local:/nreal /Network/nreal url auto,url==afp://nreal:password@ourserver.local/nreal 0 0
    # ————————————————————————————-

    how to refresh automount(login as root/su):

    sudo automount -cv

    OS X 10.4 (netinfo manager)
    LINK: http://ask.metafilter.com/54223/Help-me-automount-my-smb-share-in-Apple-OS-X-reward-inside
    in terminal.app:

    nidump fstab . > /tmp/fstab
    echo “ourservernreal /Network/nreal url url==cifs://nreal:password@ourserver/nreal 0 0″ >> /tmp/fstab
    sudo niload fstab . < /tmp/fstab
    sudo killall -HUP automount

    how to refresh automount(login as root/su):

    sudo killall -HUP automount

    QMASTER
    I had tried for some time to get shake scripts to render over our network using Qmaster but it just wouldn’t work. The QMaster logs were where I found all my errors. ‘frame 0021 could not be found’, ‘UNIX error 3 file could not be found’

    things to check

  • shake / maya / qmaster 3 node is installed on all render machines
  • the location of all your media can be accessed by all machines
  • What seemed strange was that if I logged into the xServe and executed a script via terminal with shake (to render just on the xserve) the render would complete successfully. Then it clicked that maybe the environment variables I was using in my scripts ($xxx) might not be getting recognised by Qmaster or the way Qmaster launches Shake??

    The big tip-off
    I googled for the errors I kept seeing and luckily enough this forum post popped up:
    http://www.highend3d.com/boards/index.php?showtopic=204342

    “I have pinned this down to at least one reason – that the shake qmaster isn’t picking up the NR_INCLUDE_PATH environment variable. Does anyone know where you need to set this up on a cluster node (I can get the qmasterd to pick it up but that doesn’t solve the problem!) “

    If you are trying to use Qmaster, and need to set environment variables, then you need to create a wrapper script that sets the variables and then calls the appropriate version of shake.

    For example, (this was from Apple)

    NR_INCLUDE_PATH=/Network_Applications/Shake Plugins/nreal/include;export NR_INCLUDE_PATH
    NR_ICON_PATH=/Network_Applications/Shake Plugins/nreal/icons;export NR_ICON_PATH

    umask 000

    /Applications/Shake3.50/shake.app/Contents/MacOS/shake $*
    status=$?
    if [ $status -ne 0 ]
    then
    exit $status
    fi

    Then when using Qmaster, you run the application using this
    script (saved for example as /usr/bin/shakeWrapper) which must be
    installed on all nodes in the cluster.

    Regards
    Nell

    Cheers Nell!

    I took Nell’s script, added a few lines to it and stuck it in /usr/bin/

    /usr/bin/shakeWrapper – create a file to launch Shake respecting ENV variables – later alias ‘shake’ to this file

    echo
    echo “Shake 4 running through a wrapper script – /usr/bin/shakeWrapper”
    echo

    umask 000

    /Applications/Shake/shake.app/Contents/MacOS/shake $*
    status=$?
    if [ $status -ne 0 ]
    then
    exit $status
    fi

    I added the first few lines there so when I later made an alias to this script the Shake user would have some idea what is going on when launching Shake via the terminal.

    Setting up the ENV (environment) variables…

    /etc/profile – to declare system-wide Environment variables / aliases
    (alias shake to use a wrapper to make it launch respecting/recognising the env variables)

    # System-wide .profile for sh(1)

    if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    fi

    if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
    fi

    JOBS_LOCAL=”/Volumes/otherdrive/jobs”;
    export JOBS_LOCAL

    JOBS_SERVER=”/Volumes/ourserversharepoint/jobs”;
    export JOBS_SERVER

    NR_INCLUDE_PATH=”$HOME/nreal/include”:”/Network/nreal/include/”;
    export NR_INCLUDE_PATH

    alias shake=”/usr/bin/shakeWrapper”

    *remember to enter into terminal:
    source /etc/profile

    FCS2, PSD, Motion, AJA kona 10-bit YUV and Colorista

    Recently I have noticed a few bugs with our FCS2 system.

    We are using Final Cut Studio 2 with an AJA 10bit Kona LHe card equipped MacPro 2×3GHz Quad running OSX 10.4.9.

    1. Importing PSD into FCP

    Until about a month ago I was able to import PSD files into FCP as a layered sequence. Now I don’t seem to be able to get that to happen – the file only comes in a flattened file. Not sure why

    My workaround for now is to open the PSD file in Motion as a layered comp. I think this is actually a better way to lay up gfx anyway – Motion is much faster for controlling the layers. Props to Dr Gormley for the tip!

    2. Problems playing out Motion projects in FCP

    For me one of the coolest things of working with Motion in FCP is that you can jump back and forth between the two and the embedded Motion project will update.

    But, now when I render the Motion clip and put it out to a VTR, it plays out bizarre – sometimes with a heavy PINK cast to it.

    To workaround this I changed the FCP sequence setting from ‘Render 10-bit Material in high-precision YUV’ to ‘Render in 8-bit YUV’. This seems to allow me to get SOMETHING to tape that is not screwed up – but means we are not going to tape in 10bit.

    The other way around this is to simply render a QuickTime out of Motion – but I really like the flexibility of the embedded comps in FCP – good for working with clients.

    3. Magic Bullet Colorista – no likey 10-bit sequences either

    The Colorista plugin is awesome and I use it quite a lot. But it seems to be another hater of the 10bit YUV render setting in FCP. Sometimes I render the clips with Colorista on them, and it will produce some random artifacting to the clip, sometimes random bright noise in some areas.

    Workaround: Changing the fcp sequences’ render settings to 8bit fixes this

    So I am going to suss this out and find some solutions/explanations – I will blog back about this as I go.

    Python script to get all maximum values in an image sequence

    Yesterday i fudged together a python script to use Shake and create an image that is the maximum values of that sequence.

    The output of the python script is a Shake script that contains as many FileIns as there are images in the sequence – each one slipped one frame more than the previous. Does that make any sense?

    Each image is plugged into a Max layer node and then that is plugged into the next Max layer node etc….

    So depending on the length of your sequence the Shake script can be enormous!

    Python is awesome.



    shake_maxscript_image

    Here is the script:
    shake max python script (579)

    Apple Color – First Impressions from production

    We just completed a small job for Thai Nissan’s new car “Teana”. I figured it would be a perfect opportunity to test out Apple’s Color seeing as the commercial only had 5 shots in it.

    The colouring toolset in Color is fantastic compared with FCP. There are good tools in FCP, but Color takes it to another level.

    The Workflow
    After skimming over the Color manual I had got the idea of how it is meant to work. Basically:

    Treat it as if you were taking an online edit to a telecine session.

    Understanding that makes it all so simple.

    I was making the mistake of thinking I could easily jump BACK and FORTH between FCP & Color and use lots of layers, but it is not meant to we worked that way.

    How I do this:

  • Do your best to make your get your FCP sequence to be 1 video layer
  • Make sure your sequence is either Apple ProRes or Uncompressed 10bit/8bit CODEC. These are the native CODECs for Color.
  • Make sure all the elements in the sequence are Apple ProRes or Uncompressed 10bit/8bit CODEC QuickTime movies. Nested sequences and Still frames ARE A NO NO! This may mean that you have to export out portions of your edit as QuickTime movies clips and import them back into your sequence
  • Getting there and back

    There seems to be 2 ways to get your edit from FCP to Color and back to FCP.
    1. Use the ‘send to color’ & ‘send to fcp’ option
    2. export your sequence as xml from FCP, then open it with Color, then export as xml from Color, and import into FCP.

    I used option 1 for the Nissan job, but today I have been using option 2. I prefer this option because it allows me to save the XML files where I want to (good for our current workflow).

    Observations:

  • Color keeps all project files and renders in 1 place – similar to FCP, but more strict. FCP lets you save a project where ever you want to.
  • Any translations you do in FCP on a piece of video – such as Position, Anchor, Scale, Rotate – are transferred to Color and back to FCP
  • Any cropping/filters/animation will not be visible in Color – but it will be present once you go back into FCP from Color.
  • This takes me back to what I said about “Treat it as if you were taking an online edit to a telecine session”.
  • Basically what you send to Color should be like what you might ingest from a Digibeta tape – ‘a piece of video’.
  • I think Color is a fantastic version 1 release and hopefully it means there will be a lot more cool stuff to look forward too.

    http://www.coloruser.net/
    Apple’s Color Discussion forums

    color
    Final Cut Pro
    Final Cut Pro-xml.png

    Jeremy Pronk – “Spatial Image Based Lighting”

    Jeremy has some amazing work (i believe it was his thesis?) on Spatial Image Based Lighting.

    check it out:

    http://www.happiestdays.com/sibl.php

    Overview

    The aim of this research is to investigate a spatial extension to the common image based lighting (IBL) process suitable for practical use in areas such as visual effects, animation and gaming.Â