Nuke Scripts

FileDescriptionType
LockViewerLockViewer locks a selected node to a chosen viewer (1-10). Pressing the same viewer number on a different node results in showing up the 'locked' node.py
MoveNodesMoves selected Nodes straight via Shift+Up,Shift+Down, Shift+Left or Shift+Rightpy
SetRotoLifetimeAllThis script sets the Lifetime_Type Attribute of Roto's Strokes and Shapes to "All".py


Nuke/Python Snippets

# Nuke Startup Defaults
#################################
### Global Preferences
#################################

nuke.toNode("preferences").knob('TileWidth').setValue( 80 )
nuke.toNode("preferences").knob('TileWidth').setEnabled( False )
nuke.toNode("preferences").knob('TileHeight').setValue( 20 )
nuke.toNode("preferences").knob('TileHeight').setEnabled( False )
nuke.toNode("preferences").knob('GridWidth').setValue( 50 )
nuke.toNode("preferences").knob('GridWidth').setEnabled( False )
nuke.toNode("preferences").knob('GridHeight').setValue( 25 )
nuke.toNode("preferences").knob('GridHeight').setEnabled( False )
nuke.toNode("preferences").knob('dag_snap_threshold').setValue( 12 )
nuke.toNode("preferences").knob('dag_snap_threshold').setEnabled( False )

nuke.toNode("preferences").knob('SnapToNode').setValue( 1 )
nuke.toNode("preferences").knob('SnapToNode').setEnabled( True )
nuke.toNode("preferences").knob('SnapToGrid').setValue( 1 )
nuke.toNode("preferences").knob('SnapToGrid').setEnabled( False )
nuke.toNode("preferences").knob('show_grid').setValue( 1 )
nuke.toNode("preferences").knob('show_grid').setEnabled( True )

nuke.toNode("preferences").knob('DAGBackColor').setValue( 842150655 )
nuke.toNode("preferences").knob('DAGBackColor').setEnabled( False )
nuke.toNode("preferences").knob('OverlayColor').setValue( 1061109759 )
nuke.toNode("preferences").knob('OverlayColor').setEnabled( False )

# global roto autokey off
nuke.toNode("preferences").knob('DfltBezAutokey').setValue(False) 

#################################
### Global Presets / Knob Defaults	 
#################################

# render jpegs with highest quality everytime
nuke.knobDefault('Write.jpeg._jpeg_quality', '.9')
nuke.knobDefault("Write.jpeg._jpeg_sub_sampling", "4:4:4")

# set multiply channels to rgba
nuke.knobDefault("Multiply.channels", "rgba")

# set dither channels to rgba
nuke.knobDefault("Dither.channels", "rgba")

# set colorlookup channels to rgb
nuke.knobDefault("ColorLookup.channels", "rgb")

# Make quicktime output written default to sRGB color space
nuke.knobDefault('Write.mov.colorspace', 'sRGB')

# set roto output to alpha
nuke.knobDefault("Roto.output", "alpha")
nuke.knobDefault("Roto.hide_input", "0")

# set gamma channels to rgb
nuke.knobDefault("Gamma.channels", "rgb")

# set blur channels to rgb
nuke.knobDefault("Blur.channels", "rgb")

# i have big bunch of more startup defaults,
# but they rely all on a integrated pipeline serving custom needs. 

## Print Node's Knobs and Values (great hotkey assignment)
# Print Node's Knobs and Values 
valuelist = []
for i in range (nuke.selectedNode().getNumKnobs()):
    if nuke.selectedNode().knob(i).name() != "":
        valuelist.append( [nuke.selectedNode().knob(i).name(),nuke.selectedNode().knob(i).value()] )

for i in sorted( valuelist ):
    print i
# print inputs (dependencies) of a selected node
for node in nuke.selectedNode().dependencies():
    print node.name()
# print outputs (dependents) of a selected node
for node in nuke.selectedNode().dependent():
    print node.name()
# DEBUG # Callback that echoes every action inside nuke
def onKnobChanged():
	n = nuke.thisNode()
	knob = nuke.thisKnob()
	print knob.name(), " = ", knob.value()
nuke.addKnobChanged(onKnobChanged)
# print position of a selected nodes
#print position of some selected nodes
for a in nuke.selectedNodes():
	print "x: ", a.xpos(), " - y: ", a.ypos(), '\t\t', a.name()

# Lock Computer From Within Python (on windows machines)
## Lock Computer From Within Python
'''a very simple recipe to lock a users workstation using the ctypes module.  
This will lock the workstation forcing the user to re-enter their credentials or to 
switch users.  Useful for security concious applications that need to ensure user 
integrity, and protect users from themselves (to an extent). 
Tested in both WindowsXP and Windows7.'''
import ctypes
user32 = ctypes.cdll.LoadLibrary("user32.dll") 
user32.LockWorkStation()
# disable cache attribute in allNodes
for a in nuke.allNodes():
   try:
       a['cacheLocal'].setValue(0)
   except:
       pass
   try:
       a['cached'].setValue(0)
   except:
       pass
# colorcorector node with nearly the same ranges of a combustion colorcorrector
# cc with combustion ranges
set cut_paste_input [stack 0]
version 6.3 v5
push $cut_paste_input
ColorCorrect {
 lookup {shadow {curve 1 s-2.700000048 x0.4971649051 0 s0}
   midtone {1-shadow-highlight}
   highlight {curve x0.508505106 0 s0 x1 1 s2.950000048}}
 name global32
 selected true
 xpos -153
 ypos 350
}
# make a node unmoveable
s = nuke.selectedNode() 
y = s['ypos'].value() 
x = s['xpos'].value() 
s['knobChanged'].setValue(''' nuke.thisNode()['xpos'].setValue(x) nuke.thisNode()['ypos'].setValue(y) ''') 
# select "write" nodes in selection
for node in nuke.selectedNodes():
	if node.Class() == "Write":
		node.setSelected( True )
	else:
		node.setSelected( False )
# rerender 'matching' write nodes
for node in nuke.allNodes("Write"):
    if "enter_matching_string_here" in node['file'].value():
        print node.name()
        nuke.execute( node, 0, 0 ) # adjust frame range if needed
# get Strokes from Roto/Rotopaint Layer
def __getStrokes( self, layer ): 
	for element in layer: 
		if isinstance(element, nuke.rotopaint.Layer): 
			self.__getStrokes(element)
		elif isinstance(element, nuke.rotopaint.Stroke) or isinstance(element, nuke.rotopaint.Shape): 
			strokes.append(element)
	return strokes
# DependentChecker - with 2 nodes given, it checks recursively if the first node is dependent to the second
def DependentChecker( currentnode=None, searchednode=None ):
	found = 0
   #print currentnode.name(), " - ", len(currentnode.dependent(nuke.INPUTS))
	if currentnode.dependent(nuke.INPUTS):
		for n in currentnode.dependent(nuke.INPUTS):
			if n.name() == searchednode.name():
				found = 1
				#print "True -",searchednode.name(),"is dependent"
			elif found == 0:
				DependentChecker( currentnode=n, searchednode=searchednode )
		return True
# rename x to y in allNodes['label']
x = ''
y = ''
nodes = nuke.allNodes()
for node in nodes:
    searchsource = node['label'].value().rpartition("/")[2]
    if x in searchsource:
        print node.name()
        print node['label'].value().rpartition("/")[2]
        newfilename = node['label'].value().replace( 'x', 'y')
        node['label'].setValue(newfilename)
        print node['label'].value().rpartition("/")[2] +'\n'
# prints used footage folder (without duplicates)
from operator import itemgetter
nodes = []
NoDuplicatePaths = []
fnode = []
fpath = []
output = ''
fnodepathlist=[]

for node in nuke.allNodes("Read"):
	fnode.append( node.name() )
	fpath.append( node['file'].value().rpartition("/")[0] )
# fnodepathlist erstellen und sortieren nach paths . list = read1, pathofread1
fnodepathlist = zip( fnode, fpath )
fnodepathlist.sort( key=itemgetter(1) )
#reset fnode und fpath list to write sorted list
fnode = []
fpath = []
for item in fnodepathlist:
	fnode.append( item[0] )
	fpath.append( item[1] )
for item in list( set(fpath) ) :
	NoDuplicatePaths.append( item )
NoDuplicatePaths.sort()
order = 1
for item in NoDuplicatePaths :
	if order < 10:
		printorder = "0"+str(order)
	else:
		printorder = str(order)
	output += '%s : %s\n' % ( printorder, item )
	if order == len( list( set( fpath ) ) ):
		output += '\n'
	order = order+1

print output

'''
# Result:
01 : X:/Path/to/your/Footage/Folder/
02 : X:/Path/to/your/Footage/Folder/Folder1
03 : X:/Path/to/your/Footage/Folder/Folder1/Subfolder1
04 : X:/Path/to/your/Footage/Folder/Folder1/Subfolder2
05 : X:/Path/to/your/Footage/Folder/Folder2
06 : X:/Path/to/your/Footage/Folder/Folder3
07 : X:/Path/to/your/Footage/Folder/Folder4
08 : X:/Path/to/your/Footage/Folder/Folder4/Subfolder1/Subfolder1
09 : X:/Path/to/your/Footage/Folder/Folder4/Subfolder1/Subfolder2
10 : X:/Path/to/your/Footage/Folder/Folder5
'''
# traverse every file and directory in a directory tree
import os
for dirname, dirnames, filenames in os.walk('.'):
    for subdirname in dirnames:
        print os.path.join(dirname, subdirname)
    for filename in filenames:
        print os.path.join(dirname, filename)
# prints the used channels used by selected nodes
nodechannels = []
for node in nuke.selectedNodes():
	for channel in node.channels():
		nodechannels .append( channel )

channels_noduplicates = set( nodechannels  )

print '\n'.join( sorted( channels_noduplicates ) ) 
# function to generate all casings of a input string
def all_casings(input_string):
	if not input_string:
		yield ""
	else:
		first = input_string[:1]
		if first.lower() == first.upper():
			for sub_casing in all_casings(input_string[1:]):
				yield first + sub_casing
		else:
			for sub_casing in all_casings(input_string[1:]):
				yield first.lower() + sub_casing
				yield first.upper() + sub_casing


>>> [x for x in all_casings("foo")]
['foo', 'Foo', 'fOo', 'FOo', 'foO', 'FoO', 'fOO', 'FOO']
>>> list(all_casings("foo"))
['foo', 'Foo', 'fOo', 'FOo', 'foO', 'FoO', 'fOO', 'FOO']
# various tcl commands
#get version number in nuke filename (#v002)
[regexp -inline -- {v\d+} [python str(nuke.root().name())] ]

#write nodes filename from topmost read:
[lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]

#write to same folder as the original file but with a new filename extension:
[file dirname [knob [topnode].file]]/[lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]_conv.%04d.exr

#create write node with filename from topmost read node:
[lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]

#gets labelname of input's input
[value input.input[value input.which].label]

#Root dir:
[file dirname [knob [topnode].file]]
[file tail [knob [topnode].file]]

#File name:
[file tail [knob [topnode].file]]

#File extension:
[file extension [knob [topnode].file]] 

gets labelname of the right before switches input's input
[value input.input[value input.which].label]

Dualscreen Wallpapers

Botanic Garden




A decent panoramic wallpaper taken with my Canon 1DsMark II.
This Panorama contains 12 vertical images, refurbished in Photoshop.

Download - JPG - 3840x1200 Pixel - 500kb