BASIC NUKE SCRIPTS
#*********************************************************************
# content = Nuke: examples
# date = 2020-04-01
#
# author = Avijit Panda
# Mob = +91 9734317114
# email = panda.aavijit@gmail.com@gmail.com
#*********************************************************************
# EXPRESSION
# TCL
[value root.name]
[value Write1.file]
[value root.fps]
# PYTHON
nuke.root().knob('fps').value()
# Python in TCL
[python nuke.root().knob('name').value()]
#*********************************************************************
# To get the name of single selected Node:
1
| nuke.selectedNode().name() |
# To get the name of all selected Nodes:
1
2
| for i in nuke.selectedNodes(): print i.name() |
# To get the particular type of nodes:
1
2
| for n in nuke.allNodes( 'Blur' ): print n.name() |
# To get the dependent input node:
1
2
3
| myNode = nuke.toNode( 'Blur1' ) for k in nuke.dependentNodes(nuke.INPUTS,myNode): print k.name() |
# To get nodes from the Group node:
1
2
3
| myGroup = nuke.toNode( 'Group1' ) for l in nuke.allNodes( 'Blur' ,group = myGroup): print l.name() |
1
2
3
| myGroup = nuke.toNode( 'Group1' ) for j in myGroup.selectedNodes(): print j.name()< / span> |
# To set auto label for creating nodes:
1
2
3
4
5
| def showFocal(): n = nuke.thisNode() label = '%s\nfocal %s' % (n.name(),n[ 'focal' ].value()) return label nuke.addAutolabel(showFocal,nodeClass = 'Camera2' ) |
# To set autolabel for the particular node
1
| nuke.toNode( 'Camera1' )[ 'autolabel' ].setValue( 'showFocal()' ) |
# To set autolabel for the selected nodes
1
| nuke.selectedNode()[ 'autolabel' ].setValue( 'showFocal()' ) |
# To set position for creating nodes:
1
2
3
| nuke.nodes.NoOp(xPos = 100 ,Ypos = 100 ,label = "100/100" ) marker = nuke.nodes.Dot() marker.setXYpos( 0 ) |
# To zoom the workflow nodes:
1
2
3
| nuke.zoom( 0 ) #to fit in thenode graph nuke.zoom( 3 ,node.Xpos,nodeYpos) |
# Create Message Dialog box:
1
| nuke.message('Hello World")
|
# To show the Channel box of the Node:
1
2
3
|
def showChannels():
return '\n'.join(nuke.thisNode().channels())
nuke.display( 'showChannels()' ,nuke.selectedNode(), 'Node Channel' ) |
# To Change the label of selected Nodes
1
2
3
4
| txt = nuke.getInput( 'change Label' , 'new label' ) if not txt = = None : for n in nuke.selectedNodes(): n.knob( 'label' ).setValue(txt) |
# To Change the tile_color of selected Nodes
1
2
3
4
5
| col = nuke.getColor() glcol = nuke.getColor() if not col = = 'None' : for n in nuke.selectedNodes(): n.knob( 'tile_color' ).setValue(col) |
# To get the details from notepad to Sticky note Node
1
2
3
4
5
6
7
8
| dir = 'D:/...' # Location of the file Directory filePath = nuke.getFilename( 'Get Details' , '*.txt *.xml' , dir ) if not filePath = = None : file = open (filePath, 'r' ) content = file .read() file .close() htmlstr = '<img src = "D:/...">' # Location of the image Directory nuke.nodes.StickyNote(label = htmlstr + '\n' + content , note_font_size = 20 )
|
# *******************************************************
# EXAMPLES
1
2
|
import nuke
nuke.scriptSaveAs("C:/Users/panda/Desktop/aaa.nk")
|
def save_scene():
nuke.scriptSaveAs("D:/Avijit/sfa_nuke.nk")
# *******************************************************
# OPEN current scene folder
import os
import webbrowser
import nuke
path = nuke.root().knob('name').value() # scene path
print path
path = os.path.dirname(path) # without: open file
print path
webbrowser.open(path) # open path
# *******************************************************
# REPLACE old with new directory part
import nuke
node_type = 'Read'
old_path_part = r'D:/wallpaper2'
new_path_part = r'D:/wallpaper'
for read in nuke.allNodes(node_type):
path = read.knob('file').getValue()
path = path.replace(old_path_part, new_path_part)
read.knob('file').setValue(path)
# *******************************************************
# CREATE fg-bg node network
read_fg = nuke.nodes.Read()
read_bg = nuke.nodes.Read()
merge = nuke.nodes.Merge()
write = nuke.nodes.Write()
merge.setInput(0, read_bg)
merge.setInput(1, read_fg)
write.setInput(0, merge)
read_bg.knob('file').setValue('D:/Avijit/bg.png')
read_fg.knob('file').setValue('D:/Avijit/fg.png')
write.knob('file').setValue('D:/Avijit/rlt.png')
# *******************************************************
# CREATE Render Folder [paste this (write>pytho>before render)]
import os
if not os.path.isdir(os.path.dirname(nuke.thisNode()['file'].evaluate())):
os.makedirs(os.path.dirname(nuke.thisNode()['file'].evaluate()))
# *******************************************************
# CREATE Write Node with file name. after paste the render folder script
import nuke
import os
w = nuke.createNode('Write', inpanel=True)
count = 1
while nuke.exists('AvijitWrite' + str(count)): # Change The write Name
count += 1
w.knob('name').setValue('AvijitWrite' + str(count)) # Change The write Name
t = nuke.Tab_Knob("Path Fragments")
w.addKnob(t)
w.addKnob(nuke.EvalString_Knob('proj_root', 'Project Root', '[join [lrange [split [value root.name] / ] 0 4 ] / ]'))
w.addKnob(nuke.EvalString_Knob('seq', 'Sequence', '[lrange [split [value root.name] / ] 5 5 ]'))
w.addKnob(nuke.EvalString_Knob('shot', 'Shot Name', '[lrange [split [value root.name] / ] 6 6 ]'))
w.addKnob(nuke.EvalString_Knob('script', 'Script Name', '[file rootname [file tail [value root.name] ] ]'))
output_path = "[value proj_root]/[value seq]/[value shot]/output/[value script]/[value script].%04d.jpeg" # extension format (.jpeg)
w.knob('file').fromScript(output_path)
w.knob('_jpeg_quality').setValue(float(1)) # run the line for jpeg render
w.knob('_jpeg_sub_sampling').setValue('4:4:4') # run the line for jpeg render
print path
# *******************************************************
# CREATE Write Node from file
import nuke
import os
r = nuke.selectedNode()
colourspace = r.knob('colorspace').getValue()
f = r.knob('file').getValue()
filename, file_extension = os.path.splitext(f)
format = file_extension.split(".")[-1]
input = os.path.split(f)[0]
SH_dir_name = os.path.basename('[file rootname [file tail [value root.name] ] ]') # sh_dir name (input)
path = os.path.split(input)[0]
SH_name_with_exe = SH_dir_name + '_%04d' + '.tga' # extension format (.tga)
output =(path + '/lit_compoutput/' + SH_dir_name ) # output folder name (lit_compoutput)
if not os.path.exists(output):
os.makedirs(output)
output_path = (output + '/' + SH_name_with_exe)
w = nuke.createNode('Write')
w.knob('colorspace').setValue(int(colourspace))
w.knob('file_type').setValue(format)
w.knob('file').setValue(output_path)
w.knob('channels').setValue('rgba')
w.knob('compression').setValue('none') # run the line for tga render
w.knob('_jpeg_quality').setValue(float(1)) # run the line for jpeg render
w.knob('_jpeg_sub_sampling').setValue('4:4:4') # run the line for jpeg render
print path
# *******************************************************
# Add Value in & Others Node (change Shuffle)
for node in nuke.allNodes('Shuffle'):
node.knob("label").setValue("[value in]")
# *******************************************************
# Modify check box value True/False
for node in nuke.selectedNodes():
node.knob("auto_alpha").setValue(True)
No comments:
Post a Comment