Nuke scripting – let’s get ordely random

#update – here is an example of the script in effect


I needed a function for my upcoming Escort cinematic in Nuke, it didn’t exist out of the box (not that I found anyway).

I needed to be able to create a dynamic random character output from the text node (yay for broken robot HUD’s):

  • Random numbers/integers
  • Random characters
  • The ability to disable these at a given time/frame
  • the ability to choose how many values to display (avoid repeating the statement repeatedly)
I’ve got a background in programming (semester at UTAS) but haven’t delved into python to often, my love affair with nuke might change this.
I got my code working and now for the next step… getting nuke to load this automatically so I need not worry about pasting it in through the script editor. Easy? well yes and no, I have trouble with all the tutorial material being for Macs, but I digress.

So I’ve modified/created my file (relax not the main one… the user one)

After breaking down a little I caved and watched the intro to external .py scripts here And pow, new functionality added!


I’m loving the ability to code straight into nuke, the amount of functionality is staggering and I am excited by the things I want to do, yeah this code is pretty simple but I get exactly the control I wanted out of it.

If I get round to doing tutorials (max/maya/nuke) I’ll definitely include a scripting component.

#sorry for the formatting being butchered.


import nuke
#startFrame = frame to lock number
#staticInt = number to show after start frame
#digitsAmountStartdigitsAmountEnd = define the range of digits to show, allows
#big number to be shown easily
def randIntLimit(startFrame, staticInt, digitsAmountStart, digitsAmountEnd):
import random
randint = “0”
if startFrame > nuke.frame():
for i in range(digitsAmountStart, digitsAmountEnd):
randint += str(random.randrange(0,10))
randint = staticInt
return randint

def randCharLimit(startFrame, staticChar, digitsAmountStart, digitsAmountEnd):
import random
ch = “”
if startFrame > nuke.frame():
for i in range(digitsAmountStart, digitsAmountEnd):
rand = random.randint(0,35)
if rand < 10:
ch += str(rand)
ch += chr(rand + 55)
ch = staticChar

return ch



One thought on “Nuke scripting – let’s get ordely random

  1. Pingback: Callan W » Pulses and nodes – it’s exciting!

Comments are closed.