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()

Popular posts from this blog

2D Volumetric rays in nuke

Nuke workFlow optimisation TIPS

Export Maya camera and Objects to Nuke