change Roto Views to left and right

RotoViewsPanel.py

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.

RotoViewsPanel.py.

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.


result:
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.addKnob(self.changeKnob)

        self.viewsKnob = nuke.MultiView_Knob('views')
        self.addKnob(self.viewsKnob)
        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):
        self.knobChanged(knob)
        if knob == self.okButton:
            self.finishModalDialog( True )

            if self.changeKnob.value() == 'all RotoPaint nodes':
                self.__nodes = nuke.allNodes('RotoPaint')
                self.__nodes.extend(nuke.allNodes('Roto'))
            elif self.changeKnob.value() == 'selected RotoPaint nodes':
                self.__nodes = nuke.selectedNodes('RotoPaint')
                self.__nodes.extend(nuke.selectedNodes('Roto')) 
            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):
                shapes.extend(self.getShapes(element))
            elif isinstance(element, nuke.rotopaint.Shape) or isinstance(element, nuke.rotopaint.Stroke):
                shapes.append(element)
        return shapes

    def changeViews(self, nodes, views):
        for n in nodes:
            print n.name()
            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.remove('nv')
                  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
                else:                   
                    count = 1
                for view in views:
                   index = float(nuke.views().index(view)+1)
                   attrs.add('view%s'% count, index)
                   count +=1
            k.changed()


p = RotoViewsPanel().showModalDialog()

Popular posts from this blog

2D Volumetric rays in nuke

Nuke workFlow optimisation TIPS

Export Maya camera and Objects to Nuke