Code
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:
1 2 3 |
import os if not os.path.isdir(os.path.dirname(nuke.thisNode()['file'].evaluate())): os.makedirs(os.path.dirname(nuke.thisNode()['file'].evaluate())) |
Split and use topnode’s filename
For file conversions or prep-jobs, if you want to use the original input’s filename in the final write node, you can use the following snippet of code.
1 |
/[join [lrange [split [file dirname [value [topnode].file] ] "/"] 1 6] "/"]/2D/PRERENDER/[lrange [split [file dirname [value [topnode].file] ] "/"] 9 9]_DENOISED/[lindex [split [file tail [knob [topnode].file]] .] 0]_denoised_v02.%04d[file extension [knob [topnode].file]] |
random() function in tcl
Well. It goes like this:
1 |
(random(seed, frame * frequency) * amplitude ) + offset |
Copy files on os level via python
This script copies the file of a Read node to a specific folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import shutil import os readNode = nuke.toNode('Read12') path = readNode["file"].getValue() destfolder = "C:/Users/sschweiger/Desktop/test/" srcfolder = path.split("/")[-2] srcname = path.split("/")[-1] srcSize = os.path.getsize(path) if not os.path.isfile(destfolder): nuke.message('Copypocess for Videofile '+path.split("/")[-1]+' will start after klicking "OK"!'+' Wait for Message before continue!') shutil.copy2(path, destfolder) destSize = os.path.getsize(destfolder+srcname) x=0 while (x!=1): if srcSize==destSize: x=1 else: x=0 nuke.message('Copied sucsessfully!') |
Disable knobs on a certain node with python
1 2 |
x = nuke.toNode("YourNode") x['knob'].setEnabled(False) |
To do this for all knobs, just put it in a loop:
1 2 3 4 5 |
x = nuke.toNode("YourNode") x['knob'].setEnabled(False) for i in x.allKnobs(): [i.name()].setEnabled(False) |
Execute writenode via python
1 2 3 |
write = nuke.toNode('YourWritenode') nuke.execute(write,firstframe,lastframe) |
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()”
1 2 3 4 5 6 7 8 9 10 11 12 |
x = nuke.toNode("YourNode") # get first an last frame from Script and convert them into integer first = int(nuke.Root()['first_frame'].getValue()) last = int(nuke.Root()['last_frame'].getValue()) x['knobname'].setAnimated(0) # set value in all frames for i in range(first,last): nuke.activeViewer().frameControl(i) x['knobname'].setValueAt(value,i) |
Create knobs with python
Syntax to create knobs (in this example a text-knob):
1 2 3 |
c = nuke.toNode("YourNode") text = nuke.Text_Knob(name,label,"text") c.addKnob(knob) |
And here a short list of the most-needed knobs:
1 2 3 4 |
nuke.PyScript_Knob(name,label,py-script) nuke.Text_Knob(name,label,Text) nuke.Boolean_Knob(name,label) nuke.Enumeration_Knob(name,label,['value1', 'value2', 'value3']) |
Hide unconnected inputs on selected nodes
Just a few lines to hide all not connected inputs. In this example the script touches all Beziers.
1 2 3 4 5 6 7 |
for x in nuke.allNodes("Bezier"): if x.input(0): pass else: x["hide_input"].setValue("1") print x["label"].value() |
Sample image from within the expression node
To sample the incoming colour values, in an expression node type the following for the required channels:
1 |
y==floor(r(x, pos.y)*height*mult)?1:0 |