To get the name of the Group of currently selected node

To get the name of the Group of currently selected node:

from __future__ import with_statement

for n in nuke.allNodes('Group'):
    grp = nuke.toNode(n.name())
    with grp :
        if nuke.selectedNodes():
            print "\nGroup Name:"+n.name()
            for nodes in nuke.selectedNodes():
                print "\tSelected Nodes:"+nodes.name()
Advertisements

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)

CGSociety Lighting Challenge

Recently my entry for mad science(CGSOCIETY -LIGHTING CHALLENGE) have been selected for the final gallery of 3drender.com.This is my second challenge,i’m participating.Both my entries has been in to the final gallery.Here are those two images.

Mad Science
It was done using Maya-mental Ray and nuke.
My primary motive here was to learn about maya_mia materials and nuke’s linear workflow.

Room Interior – Afraid of the dark:

It was shaded and lighted using maya software renderer and composited in digital fusion.

3drender Gallery

Mad science: http://www.3drender.com/challenges/madScience/index.html

Bedroom: http://www.3drender.com/challenges/bedroom/index.html

Another Command to get filename in the Nuke Read Node

The main advantage of this command is that ,we can connect any input Read node [Example. Read1 or Read3 or Read4.,].it will give correct filename from the Read node.No need to specify the name of the Read Node.

[file tail [file rootname [metadata input/filename]]]

Here,
Metadata is a set of information about an image embedded in the image file.This may include the image’s original bit depth,width and height etc.,

How to get Filename without Directory path & extension from Read Node in Nuke?

Wanna Test!

Step1 : Pick the Text Node from the Draw Menu.

Step2 : Connect image Read Node into Text Node.

Step3 : Type the following Command on Message Field at Text Node.
[file tail [file rootname [value  readNodeName.file] ] ]

Here,
We should specify the name of the Read Node.

file tail – For Remove Directory Path.

file rootname – For Remove Extension.

Example : [file tail [file rootname [value Read1.file] ] ]

How to Create and Register your Custom Viewer Process Gizmo in Nuke?

Custom Viewer Process Gizmo:

Step 1:    Create the  process nodes in node graph and make it them as Group Node.i.e., (Select all Process nodes and  press Ctrl+g).

Step 2:    Select the Group node and Click export as gizmo button in Group node Property and save it in root Directory.

Step 3:    And register your Gizmo by following python script and save as init.py.if already init.py is there.Just insert the lines in the init.py file

nuke.ViewerProcess.register(“Title_of_Gizmo”,nuke.Node,(“Your_Saved_Gizmo_Name”, “”))

Example: nuke.ViewerProcess.register(“ForTest”,nuke.Node,(“TestTool”, “”))

Step 4:    Restart Nuke & View your Gizmo in Viewer popup list.

How to add user defined Gizmos/Plugins in Nuke Toolbar?

By Manual:

Step 1 :    Create and Copy the Gizmo into the root Directory “C:\Documents and Settings\Administrator\.nuke“.

Step 2 :    Goto etc… –> All Plugins –> Update from ToolBar.Your gizmo will be updated in the toolbar.

Step 3 :    Again Goto etc… –> All Plugins –> An Alphabetic List will be display and pick your Gizmo in it.

Using Python Script:

Step 1 :    Copy the Gizmo into the root Directory “C:\Documents and Settings\Administrator\.nuke”.

Step 2 :    Type the following Python script in script editor and Save as menu.py in root Directory.

if already menu.py is there.Just insert the lines in the menu.py file

toolbar = nuke.menu(“Nodes”)
toolbar.addCommand(“other/SliceTool”,’nuke.createNode(“SliceTool”)’)

Note : Here SliceTool is one of the User-Defined Tool For Nuke Color Management.

Step 3 :    An icon will be display in the toolbar (or) right click from the Node editor to get your Gizmo  .