Basic Nuke Scripts

# To get the name of  single selected Node:

nuke.selectedNode().name()

# To get the name of all selected Nodes:

for i in nuke.selectedNodes():
    print i.name()

# To get the particular type of nodes:

for n in nuke.allNodes('Blur'):
    print n.name()

# To get the dependent input node:

myNode = nuke.toNode('Blur1')
for k in nuke.dependentNodes(nuke.INPUTS,myNode):
    print k.name()

# To get nodes from the Group node:

myGroup = nuke.toNode('Group1')
for l in nuke.allNodes('Blur',group =myGroup):
    print l.name()
myGroup = nuke.toNode('Group1')
for j in myGroup.selectedNodes():
    print j.name()</span>

# To set auto label for creating nodes:

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

nuke.toNode('Camera1')['autolabel'].setValue('showFocal()')

# To set autolabel for the selected nodes

nuke.selectedNode()['autolabel'].setValue('showFocal()')

# To set position for creating nodes:

nuke.nodes.NoOp(xPos=100,Ypos=100,label="100/100")
marker = nuke.nodes.Dot()
marker.setXYpos(0)

# To zoom the workflow nodes:

nuke.zoom(0) #to fit in thenode graph

nuke.zoom(3,node.Xpos,nodeYpos)

# Create Message Dialog box:

nuke.message('Hello World")

# To show the Channel box of the Node:

def showChannels():
    return '\n'.join(nuke.thisNode().channels())
nuke.display('showChannels()',nuke.selectedNode(),'Node Channel')

# To Change the label of selected Nodes

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

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

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 = '&lt;img src = "D:/..."&gt;' # Location of the image Directory
nuke.nodes.StickyNote(label =htmlstr + '\n' + content , note_font_size=20)