Wednesday, June 27, 2012

Import fbx camera

Import fbx camera script will add a camera node and import the camera data from the fbx file based on selected "ReadGeo" node.

Usually we import our objects into nuke as a .fbx file. After importing the .fbx file will do the same thing for import the camera from the same file.  To do that go to toolbar-->3D-->Camera... check the "read from the file" and then import the .fbx file by clicking file browser.

To get reduce the above timing. I created this small "importFbxCamera" python script. 

Import your object files by "ReadGeo" node in nuke. Select the "ReadGeo" node and run this script.

It will automatically create a "camera" node and import the camera data from the .fbx file and create a backdrop with shot name.

If you have not selected any nodes this script will show a message...
   "select ReadGeo node to import camera"


Your camera will imported into nuke with name.

import nuke
import nukescripts
def importFbxCamera():
    a = None
     a = nuke.selectedNode()
    except ValueError: # no node selected

    if a is not None:
        path =a.knob('file').value()
        s = path.split('/')[-1]
        x = s.split('.')[-0]
        name = x + ('_Camera')
        d = a.xpos() + 250
        c = nuke.createNode("Camera2")
        b = nukescripts.autoBackdrop().setName(name)
        nuke.message('select ReadGeo node to import camera')

add these lines into your
n = nuke.toolbar('Nodes')
n.addCommand('Test/importFbxCamera', 'importFbxCamera.importFbxCamera()')

Wednesday, June 20, 2012

python scripts for daily work on nuke

I'm updating regularly this post with "Tiny, Tiny " python scripts for daily uses in nuke.

1. For define roto nodes output.

Usually  we set the roto node output to "alpha" and premultiply to "rgb" for getting the premultiplied output. like below image:

rotoOut python script:
This script will do this work by a single mouse click are a short-cut key.

import nuke
def rotoOut():
    for s in nuke.selectedNodes():

save this as file into your custom python or gizmo DIR.

This script works only selected roto nodes. If you want to make it work with all roto nodes in inside nuke means, youe need to change the 3rd line like this...

import nuke
def rotoOut():
    for s in nuke.allNodes('Roto'):

2. Shuffle the image based matte to alpha channel.

Usually nuke consider single channel as red channel inside the nuke. If you import single channel image files into nuke, nuke display the channel onto the red channel only. We need to do shuffle the the "red" to "alpha" for get alpha channel from the image based matte files. 

This little py script will do this for us:

import nuke
def shuffleRedOnly():
    s1 = nuke.createNode('Shuffle')

save this as shuffleRedOnly().py file into your custom python or gizmo DIR.

3. Disable nodes via expression.
Disable a node in nuke between frames is help you lot off time. Put this expression on the disable knob off any node in nuke and it will automatically disable the nodes on the mentioned frames before and after.

Below expression for in between two values:
frame < 10 || frame >20

Only for before:
frame < 10
Only for after:
frame >20

You can assign this via script editor by following python command:

for s in nuke.selectedNodes():
    s['disable'].setValue("frame < 10 || frame > 20")

4. Reload read nodes.
When working with CG (3D) compositing, Inputs are updated regularly by new version or overwritten. 3D artist says to you, hey i overwritten the files with new render. So we need to reload all the read nodes. This little code will reload all the read nodes at a time.
[s.knob('reload').execute() for s in nuke.allNodes() if s.Class=='Read']
for s in nuke.allNodes('Read'):

5. Disable all the Denoise node inside nuke. 
 (Denoise node having different Class name)

for s in nuke.allNodes(""):

For find the nodes Class name ( like Denoise node, it has different Class ) use following command.
a = nuke.selectedNode()
print a.Class()

Friday, June 15, 2012

change Roto Views to left and right

This little python script will help you lot when working with stereoscopic conversion. While Import roto nodes from silhouette, mocha and other software’s, Imported roto nodes are output the channels only on "Left" view.

Like below image.

 We have to change the roto shapes view on both "left & right" for stereo conversion. To do that, manually select all rotoshapes and set the view on "left - right". This may take lot of time to do this on bigger shots. So how to reduce this manual work. Here is the solution for that.

This script will pop-up a window for setting the selected or all roto nodes views to left are right only are Both. Run this script on nukes script editor and enjoy.

Hope this script will help you friends.

RotoViewsPanel script:

class RotoViewsPanel(nukescripts.PythonPanel):
    def __init__(self):
        import nuke.rotopaint
        super(RotoViewsPanel,self).__init__('Change views on RotoPaint Nodes...' )

        self.changeKnob = nuke.Enumeration_Knob('change', 'change', ['all RotoPaint nodes', 'selected RotoPaint nodes'])

        self.viewsKnob = nuke.MultiView_Knob('views')
        self.viewsKnob.setValue((' ').join(nuke.views()))

        self.okButton = nuke.Script_Knob( "Change Views" )
        self.addKnob( self.okButton )
        self.okButton.setFlag( nuke.STARTLINE )
        self.cancelButton = nuke.Script_Knob( "Cancel" )
        self.addKnob( self.cancelButton )

    def knobChangedCallback(self, knob):
        if knob == self.okButton:
            self.finishModalDialog( True )

            if self.changeKnob.value() == 'all RotoPaint nodes':
                self.__nodes = nuke.allNodes('RotoPaint')
            elif self.changeKnob.value() == 'selected RotoPaint nodes':
                self.__nodes = nuke.selectedNodes('RotoPaint')
            self.__views =  self.viewsKnob.value().split(' ')

            self.changeViews(self.__nodes, self.__views)

        elif knob == self.cancelButton:
            self.finishModalDialog( False )

    def getShapes(self, layer):
        shapes = []
        for element in layer:
            if isinstance(element, nuke.rotopaint.Layer):
            elif isinstance(element, nuke.rotopaint.Shape) or isinstance(element, nuke.rotopaint.Stroke):
        return shapes

    def changeViews(self, nodes, views):
        for n in nodes:
            k = n['curves']
            shapes = self.getShapes(k.rootLayer)
            for s in shapes:
                attrs = s.getAttributes()
                # reset the number of views attribute
                if 'nv' in attrs:
                  attrs.add('nv', len(views))

                # delete any previous view attributes
                count = 1
                while ('view%s' % count) in attrs:             
                  attrs.remove('view%s'% count)
                  count +=1

                # handle no selected views
                if views == [''] :
                  attrs.add('view1', 0.0)
                # handle any other number of views
                    count = 1
                for view in views:
                   index = float(nuke.views().index(view)+1)
                   attrs.add('view%s'% count, index)
                   count +=1

p = RotoViewsPanel().showModalDialog()

scale up and down cornerpin node

global scale up and down cornerpin This script help you to global scale up or down the selected cornerpin. Recently i had situation to ...