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()
Hi,
ReplyDeleteI'm trying to find a way to assign random colors to all the existing rotoshapes within a script.
n = nuke.selectedNode()
for item in n['curves'].rootLayer:
attr = item.getAttributes()
attr.set(nuke.frame(), 'r', 1.0)
attr.set(nuke.frame(), 'g', 1.0)
attr.set(nuke.frame(), 'b', 1.0)
Any idea who to do that?
Many Thanks
Sam
Here is the code for you....
ReplyDeletedef randomRotoColor():
rotoNode = nuke.selectedNode()
rotoCurve = rotoNode['curves']
rotoRoot = rotoCurve.rootLayer
for i in rotoRoot:
if isinstance(i, nuke.rotopaint.Shape):
attrs = i.getAttributes()
randR = nuke.expression('random()')
randG = nuke.expression('random()')
randB = nuke.expression('random()')
attrs.set('r', randR)
attrs.set('g', randG)
attrs.set('b', randB)
randomRotoColor()
wow, this is great thanks! I wasn't expecting you to give me the actual code! It's working - I've got only one issue, once the colours are assigned it doesn't update the viewer unless you select the rotoshapes so you can see the colours! Did you come across this too? Thanks
DeleteHi sam this is bug in nuke. I hope in future release they have going to fix that...
DeleteHere is the another code which is work with child Layers also.
import nuke
import math
def randomRotoColor(elem):
for i in elem:
if isinstance(i, nuke.rotopaint.Layer):
randomRotoColor(i)
elif isinstance(i, nuke.rotopaint.Shape):
attrs = i.getAttributes()
randR = nuke.expression('random()')
randG = nuke.expression('random()')
randB = nuke.expression('random()')
attrs.set('r', randR)
attrs.set('g', randG)
attrs.set('b', randB)
rotoNode = nuke.selectedNode()
rotoCurve = rotoNode['curves']
rotoRoot = rotoCurve.rootLayer
randomRotoColor(rotoRoot)
thanks man, i'm trying to make it work for a group consisted of rotoshapes now - no luck so far!
ReplyDeleteby the way, i found a little trick to update the viewer with the new colours; just add this at bottom of the code:
nuke.frame(nuke.frame()+1)
by the way - I need to apply the same colour to all the children ... so still trying to use your previous code
ReplyDeletebelow code will apply "Gray" color to all the shapes. If you want to assign different color, Then try with some other color values on "attrs.set('r', 0.5)" lines. This code works with group node also.
Deletedef randomRotoColor(elem):
for i in elem:
if isinstance(i, nuke.rotopaint.Layer):
randomRotoColor(i)
elif isinstance(i, nuke.rotopaint.Shape):
attrs = i.getAttributes()
attrs.set('r', 0.5)
attrs.set('g', 0.5)
attrs.set('b', 0.5)
tos = []
for a in nuke.toNode('Group1').nodes():
if a.Class()=='Roto':
tos.append(a)
for b in tos:
rotoCurve = b['curves']
rotoRoot = rotoCurve.rootLayer
randomRotoColor(rotoRoot)