shuffleChannels v1.0


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Pau Rocher
Creates a pretty tree out of channel layers selected from a panel.
Requirements:
6.0, 6.1, 6.2, 6.3, 7.0 or later
12 Oct 2012
300
1
2
import shuffleChannels
nuke.menu('Nodes').addCommand ('shuffleChannels', 'shuffleChannels.getData()', icon = 'Shuffle.png')

 

Features:

Produces clean and configurable comp trees.

Easy way to split the layers out of a CG render.

Can store presets.

Plenty of preferences to configure the resulting tree.

 

 

Tutorial:

1. Select a node

2. Press the button

3. Choose the layers you want to expose

4. Set your Preferences in the Prefs tab

4. Press OK and enjoy a nice tree!

 

 

Notes:

- The very first time you open the panel you won't be able to save any preset because the preferences file (created in your .nuke folder) will not yet be created. Just press OK, then relaunch the panel and everything will behave propperly.

- The backDrop node adopts a weird width when the separation slider is less than 200 (more or less I think ...)

- If you get a weird problem, delete the preferences file (in your .nuke folder) and all should be good ... This should only happen if you happen to edit the prefs file manually (which you don't want to do :) )

- Havn't tested it on MacOs or Windows ...

Enjoy, and again: comments, suggestions and critiques are welcome!

.p!

 

shuffleChannelsImg001

shuffleChannelsImg002shuffleChannelsImg003shuffleChannelsImg004
Please login in order to download these files.

Comments   

 
# Dmitry Kornilov 2021-03-26 09:30
Nuke 13

exec "self.layer%s = ''" %( i )
^
SyntaxError: invalid syntax
 
 
# John Corbett 2021-11-15 18:14
Had some issues converting this to python 3. Here a version of it working in Nuke 13:

####pythone code by Pau Rocher###
####bikura at gmail dot com######

import nuke
import nukescripts
import os
import traceback
import getpass

class shuffleChannels (nukescripts.Py thonPanel):
def __init__(self, n):
nukescripts.Pyt honPanel.__init __(self, 'shuffle channels')
self.n = n
self.channels = self.n.channels ()

#def builder(self):
###layers list builder
self.layers = []
for i in range ( len ( self.channels ) ):
if self.channels.s plit('.')[0] not in self.layers :
self.layers.app end ( self.channels.s plit('.')[0] )

#UI######################################################################################################################
self.tabGroup = nuke.BeginTabGr oup_Knob ('tabGroup', '')
self.addKnob (self.tabGroup)
##layersTab
self.layersTab = nuke.Tab_Knob ('layersTab', 'layers')
self.addKnob (self.layersTab )

self.selectedNo deName = nuke.Text_Knob ( 'selectedNodeNa me', 'selected node: ', '%s, %s node' %( self.n.name(), self.n.Class() ) )
self.addKnob (self.selectedNo deName)

self.separator = nuke.Text_Knob ( 'separator', '')
self.addKnob (self.separator )

self.presets = nuke.Enumeratio n_Knob ('presets', 'presets', [' '])
self.addKnob (self.presets)

self.savePreset = nuke.PyScript_K nob ('savePreset', 'save preset', 'shuffleChannel s.savePreset()' )
self.addKnob (self.savePrese t)

self.removePres et = nuke.PyScript_K nob ('deletePreset' , 'delete preset', 'shuffleChannel s.deletePreset( )')
self.addKnob (self.removePres et)

for i in range ( len ( self.layers ) ):
exec("self.laye r%s = ''" %( i ))
exec("self.laye r%s = nuke.Boolean_Kn ob ('layer%s', '%s')" %( i, i, self.layers ))
exec("self.addK nob (self.layer%s)" %i)
exec("self.laye r%s.setFlag(4096)" %i)

#self.selectAll Layers = nuke.PyScript_K nob ('selectAllLaye rs', 'select all layers', "shuffleChannel s.selectAll()")
#self.addKnob (self.selectAll Layers)
#self.selectAll Layers.setFlag(4096)

#self.deselectA llLayers = nuke.PyScript_K nob ('deselectAllLa yers', 'deselect all layers', "shuffleChannel s.deselectAll() ")
#self.addKnob (self.deselectAllLayers)

##channelsTab
#self.channelsT ab = nuke.Tab_Knob ('channelsTab', 'channels')
#self.addKnob (self.channelsT ab)
#for i in range ( len ( self.channels ) ):
#exec "self.channel%s = ''" %( i )
#exec "self.channel%s = nuke.Boolean_Kn ob ('channel%s', '%s')" %( i, i, self.channels )
#exec "self.addKnob (self.channel%s )" %i
#exec "self.channel%s .setFlag(4096)" %i

##prefsTab
self.prefsTab = nuke.Tab_Knob ('prefsTab', 'preferences')
self.addKnob (self.prefsTab)

self.unPremult = nuke.Boolean_Kn ob ('unPremult', 'add unpremult / premult nodes')
self.addKnob (self.unPremult )
self.unPremult. setFlag (4096)

self.remove = nuke.Boolean_Kn ob ('remove', 'add remove node')
self.addKnob (self.remove)
self.remove.set Flag(4096)

self.grade = nuke.Boolean_Kn ob ('grade', 'add grade node')
self.addKnob (self.grade)
self.grade.setF lag(4096)

self.merge = nuke.Boolean_Kn ob ('merge', 'add merge node')
self.addKnob (self.merge)
self.merge.setF lag(4096)
self.operation = nuke.Enumeratio n_Knob ('operation', ' | operation', [ 'atop', 'average', 'color-burn', 'color-dodge', 'conjoint-over' , 'copy', 'difference', 'disjoint-over' , 'divide', 'exclusion', 'from', 'geometric', 'hard-light', 'hypot', 'in', 'mask', 'matte', 'max', 'min', 'minus', 'multiply', 'out', 'over', 'overlay', 'plus', 'screen', 'soft-light', 'stencil', 'under', 'xor'])
self.addKnob (self.operation )
self.operation. clearFlag(4096)
self.operation. setValue('plus' )

self.copyAlpha = nuke.Boolean_Kn ob ('copyAlpha', 'add copyAlpha node')
self.addKnob (self.copyAlpha )
self.copyAlpha. setFlag(4096)

self.noShuffLab el = nuke.Boolean_Kn ob ('noShuffLabel' , 'remove label from Shuffles')
self.addKnob (self.noShuffLab el)
self.noShuffLab el.setFlag(4096)

self.separation = nuke.Double_Kno b ('separation', 'separation between nodes')
self.addKnob (self.separatio n)
self.separation .setFlag(4096)
self.separation .setRange (100, 400)
self.separation .setDefaultValu e ([200])

self.shuffLayer sColor = nuke.ColorChip_ Knob ('shuffLayersCo lor', 'Shuffle color')
self.addKnob (self.shuffLayer sColor)
self.shuffLayer sColor.setDefaultValue([nuke.toNode('pr eferences')['NodeColour05Color'].value()])
self.shuffLayer sColor.setFlag(4096)

self.bdrop = nuke.Boolean_Kn ob ('bdrop', 'add backDrop')
self.addKnob (self.bdrop)
self.bdrop.setF lag(4096)

self.bdropColor = nuke.ColorChip_ Knob ('bdropColor', 'backDrop color')
self.addKnob (self.bdropColo r)
self.bdropColor .setDefaultValu e([926365441])

self.separation 01 = nuke.Text_Knob ('separation01' , '')
self.addKnob (self.separation 01)

self.EndTab = nuke.EndTabGrou p_Knob ('endTabGroup', '')
self.addKnob ( self.EndTab )

#self.importAll Channels = nuke.PyScript_K nob ('importAllChan nels', 'all channels', "print 'function to import all layers'")
#self.addKnob (self.importAll Channels)

def knobChanged(sel f, knob):
if knob == self.presets:
updateLayersPre set ()

def returnLayers(se lf):
return self.layers
def returnChannels( self):
return self.channels


def getData ():
#gets selected node or not
try:
global n
n = nuke.selectedNo de()
except:
nuke.message ('Select a node.')
return

#if all good launches the panel########## ############### ############### ############### #
layers = shuffleChannels (n).returnLayer s() #returns the layers list
channels = shuffleChannels (n).returnChann els() #returns the channels list
global p
p = shuffleChannels (n) #builds the panel
windowHeight = len(layers)*20+ 165 #changes panel dimensions
if windowHeight > 1000: #
windowHeight = 1000 #
p.setMinimumSiz e (600, windowHeight) #
readPrefsFile(p )
refreshPresetsM enu()
thePanel = p.showModalDial og() #launches the panel

if thePanel == False:
return
else:
pass


#beyond this point all happens after the panel has been closed#########################
#creation of the prefs variable
prefs = {'unPremult': p.unPremult.val ue(), 'remove': p.remove.value( ), 'grade': p.grade.value() , 'merge': p.merge.value() , 'operation': p.operation.val ue(), 'copyAlpha': p.copyAlpha.val ue(), 'noShuffLabel': p.noShuffLabel. value(), 'separation': p.separation.va lue(), 'shuffLayersCol or': p.shuffLayersCo lor.value(), 'bdrop': p.bdrop.value() , 'bdropColor': p.bdropColor.value()}
##writes the preferences file
writePrefsFile( p, str(prefs))
#here I collect what layers have been selected
layerList = []
for i in range (len ( layers ) ):
return_dict = {}
exec("gate = p.layer%s.value ()" %i, globals(), return_dict)
if return_dict['ga te'] == True :
layerList.appen d ( layers )

#here it will create a node tree if some layers have been selected
if len(layerList) > 0:
buildTree(layer List, prefs)
else:
return


def selectAll():
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec("(p.layer% s.setValue(True ))" %i)

def deselectAll():
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec("(p.layer% s.setValue(Fals e))" %i)


def buildTree(layer s, prefs):

nukePrefs = nuke.toNode('pr eferences')
defGoofyFootVal ue = nukePrefs['goof y_foot'].value( )
nukePrefs['goof y_foot'].setVal ue( 0 )
selNodeXPos = n.xpos()
selNodeYPos = n.ypos()

n['selected'].s etValue(False)

shuffDot0 = nuke.createNode ( 'Dot', 'selected False', False)
shuffDot0['xpos '].setValue(sel NodeXPos + 200)
shuffDot0YPos = int( selNodeYPos + 100 )
shuffDot0['ypos '].setValue( shuffDot0YPos )
shuffDot0.setIn put(0, n)

#creation of nodes
for i in range(len(layer s)):
#dots
newXPos = (prefs['separat ion']*(i+1))+sh uffDot0['xpos'] .value()
exec("shuffDot% s = nuke.createNode ('Dot', 'name shuffDot%s xpos %s ypos %s', inpanel=False)" %( i+1, i+1, newXPos , shuffDot0YPos ))
lastDot = i
exec("shuffDot% s['selected'].setValue(False)" %( len(layers) ))


##shuffles
for i in range(len(layer s)):
newXPos = (prefs['separat ion']*(i+1))+sh uffDot0['xpos'] .value()
shuf = nuke.createNode ( 'Shuffle', 'name %s in %s selected False xpos %s ypos %s' %( layers, layers, newXPos-34, shuffDot0YPos+5 0), False )
exec("shuf.setI nput(0, shuffDot%s)" %(i+1))
if i == 0:
shuf['xpos'].se tValue(newXPos- 34)
shuf['ypos'].se tValue(shuffDot 0YPos+50)
##color
if prefs['shuffLay ersColor'] != nuke.toNode('pr eferences')['NodeColour05Color'].value():
shuf['tile_color'].setValue(prefs['shuffLay ersColor'])
##label
if prefs['noShuffL abel'] == True:
shuf['label'].s etValue('')

#removes
if prefs['remove'] == True:
rem = nuke.createNode ('Remove', 'operation keep channels rgba selected False xpos %s ypos %s' %( newXPos-34, shuffDot0YPos+8 8 ), False )
rem.setInput(0, shuf)

#grades
if prefs['grade'] == True:
grad = nuke.createNode ('Grade', 'xpos %s ypos %s' %( newXPos-34, shuffDot0YPos+3 00 ), False)

#merges
if prefs['merge'] == True:
if i == 0:
dotMerge = nuke.createNode ('Dot', 'xpos %s ypos %s selected False' %( newXPos, shuffDot0YPos+5 04 ), False)
else:
exec("merge%s = nuke.createNode ('Merge', 'operation %s xpos %s ypos %s', False)" %( i, prefs['operatio n'], newXPos-34, shuffDot0YPos+5 00 ))
exec("nukescrip ts.swapAB(merge %s)" %i)
if i == 1 :
exec("merge%s.s etInput (0, dotMerge)" %i)
else:
exec("merge%s.s etInput (0, merge%s)" %( i, i-1))

#copyAlpha
if prefs['copyAlph a'] == True:
copyDot = nuke.createNode ('Dot', 'xpos %s ypos %s' % ( newXPos+prefs[' separation'], shuffDot0YPos ), False)
exec("copyDot.s etInput(0, shuffDot%s)" %(len(layers)))
copyNode = nuke.createNode ('Copy', 'xpos %s ypos %s' %( newXPos+prefs[' separation']-34 , shuffDot0YPos+4 94 ), False)
try:
exec("copyNode. setInput(0, merge%s)" %(len(layers)-1 ))
except:
pass
copyNode.setInp ut(1, copyDot)

#premult
if prefs['unPremul t'] == True:
unpr = nuke.createNode ('Unpremult', 'selected False xpos %s ypos %s channels all' %(shuffDot0.xpo s()+50, shuffDot0YPos-1 0), False)
unpr.setInput(0 , shuffDot0)
prem = nuke.createNode ('Premult', 'selected False xpos %s ypos %s channels all' %(newXPos+prefs[' separation']-34 , shuffDot0YPos+5 50), False)
prem['selected' ].setValue(Fals e)
if prefs['copyAlph a'] == True:
prem.setInput(0 , copyNode)
elif prefs['merge'] == True:
exec("prem.setInput(0 , merge%s)" %str(len(layers )-1))
exec("prem['xpo s'].setValue(me rge%s.xpos())" %str(len(layers )-1))
elif prefs['grade'] == True:
prem.setInput(0 , grad)
prem['xpos'].se tValue(grad.xpo s())
elif prefs['remove'] == True:
prem.setInput(0 , rem)
prem['xpos'].se tValue(rem.xpos ())
else:
prem.setInput(0 , shuf)
prem['xpos'].se tValue(shuf.xpo s())
shuffDot1.setIn put(0, unpr)

#backDrop
width = 0
height = 0
if prefs['bdrop'] == True:
width = ( prefs['separati on'] * (len(layers)+1) )
if prefs['unPremul t'] == True:
height = 750
elif prefs['copyAlph a'] == True:
height = 650
elif prefs['grade'] == True:
height = 500
elif prefs['merge'] == True:
height = 600
elif prefs['remove'] == True:
height = 300
else:
height = 250
if prefs['copyAlph a'] == True:
width = width + prefs['separati on']


bd = nuke.createNode ('BackdropNode', 'tile_color %s' %( prefs['bdropCol or'] ) , False)
bd['xpos'].setV alue( shuffDot0.xpos( ) - 100)
bd['ypos'].setV alue( shuffDot0.ypos( ) - 100)
bd['bdwidth'].s etValue( width )
bd['bdheight']. setValue( height )
#print 'width = %s , height = %s' %(width, height)

##resets prefs to user defined state
nukePrefs = nuke.toNode('pr eferences')
nukePrefs['goof y_foot'].setVal ue( defGoofyFootVal ue )



def readPrefsFile(p ): #reads the preferences file and sets the values on the panel knobs
try:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
except:
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("['prefs', {'none':['none' ], 'all': ['all']}]")
prefsFileW.clos e()
return
try:
prefs = eval(prefsFileR .read())[0]
for keys in prefs:
if keys != 'operation':
exec("p.%s.setV alue(%s)" %( keys, prefs[keys] ))
else:
exec("p.%s.setV alue('%s')" %( keys, prefs[keys] ))
except Exception as e:
pass
#print(traceback.format_exc(e))

def writePrefsFile( p, prefs):
try:
prefsFile = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFile. read())
prefsFile.close ()
prefsFile = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFile.write ("[%s, %s]" %(prefs, prefsFileConten t[1]))
except Exception as e:
pass
#print(traceback.format_exc(e))


def savePreset():
presetName = nuke.getInput(' name of preset')
if presetName == None or '':
return
presetLayers = []
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec(("selected = p.layer%s.value ()") %i)
if selected == True:
presetLayers.ap pend (layers)
preset = {}
preset [presetName] = presetLayers
# print 'and the preset is: %s' %preset

prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
presetsInFile [presetName] = presetLayers
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("[%s, %s]" %(prefsFileConten t[0], presetsInFile))
prefsFileW.clos e()
refreshPresetsM enu()
p.presets.setVa lue( presetName )

def deletePreset():
if p.presets.value () not in ['all', 'none']:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
if p.presets.value () not in ['all', 'none']:
del presetsInFile [ p.presets.value () ]
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("[%s, %s]" %(prefsFileConten t[0], presetsInFile))
prefsFileW.clos e()

p.presets.setVa lue('none')

refreshPresetsM enu()



def refreshPresetsM enu():
try:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
list = sorted(presetsI nFile.keys())
list.remove ('all')
list.remove('no ne')
list.insert (0, 'all')
list.insert (0, 'none')
p.presets.setVa lues( list )
except Exception as e:
pass
#print(traceback.format_exc(e))

def updateLayersPre set ():
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]

deselectAll()

chosenPreset = p.presets.value ()

layersInPreset = presetsInFile [ p.presets.value () ]

layers = shuffleChannels (n).returnLayer s()

if p.presets.value () not in ['all', 'none']:
for i in range (len(layers)):
#exec "(p.layer%s.set Value(True))" %i
exec("lay = (p.layer%s.labe l())" %i)
if lay in layersInPreset :
exec("(p.layer% s.setValue(True ))" %i)
elif p.presets.value () == 'all':
selectAll()
else:
deselectAll()
 
 
# John Corbett 2021-11-15 18:14
Had some issues converting this to python 3. Here is a version of it working in Nuke 13:

####pythone code by Pau Rocher###
####bikura at gmail dot com######

import nuke
import nukescripts
import os
import traceback
import getpass

class shuffleChannels (nukescripts.Py thonPanel):
def __init__(self, n):
nukescripts.Pyt honPanel.__init __(self, 'shuffle channels')
self.n = n
self.channels = self.n.channels ()

#def builder(self):
###layers list builder
self.layers = []
for i in range ( len ( self.channels ) ):
if self.channels.s plit('.')[0] not in self.layers :
self.layers.app end ( self.channels.s plit('.')[0] )

#UI######################################################################################################################
self.tabGroup = nuke.BeginTabGr oup_Knob ('tabGroup', '')
self.addKnob (self.tabGroup)
##layersTab
self.layersTab = nuke.Tab_Knob ('layersTab', 'layers')
self.addKnob (self.layersTab )

self.selectedNo deName = nuke.Text_Knob ( 'selectedNodeNa me', 'selected node: ', '%s, %s node' %( self.n.name(), self.n.Class() ) )
self.addKnob (self.selectedNo deName)

self.separator = nuke.Text_Knob ( 'separator', '')
self.addKnob (self.separator )

self.presets = nuke.Enumeratio n_Knob ('presets', 'presets', [' '])
self.addKnob (self.presets)

self.savePreset = nuke.PyScript_K nob ('savePreset', 'save preset', 'shuffleChannel s.savePreset()' )
self.addKnob (self.savePrese t)

self.removePres et = nuke.PyScript_K nob ('deletePreset' , 'delete preset', 'shuffleChannel s.deletePreset( )')
self.addKnob (self.removePres et)

for i in range ( len ( self.layers ) ):
exec("self.laye r%s = ''" %( i ))
exec("self.laye r%s = nuke.Boolean_Kn ob ('layer%s', '%s')" %( i, i, self.layers ))
exec("self.addK nob (self.layer%s)" %i)
exec("self.laye r%s.setFlag(4096)" %i)

#self.selectAll Layers = nuke.PyScript_K nob ('selectAllLaye rs', 'select all layers', "shuffleChannel s.selectAll()")
#self.addKnob (self.selectAll Layers)
#self.selectAll Layers.setFlag(4096)

#self.deselectA llLayers = nuke.PyScript_K nob ('deselectAllLa yers', 'deselect all layers', "shuffleChannel s.deselectAll() ")
#self.addKnob (self.deselectAllLayers)

##channelsTab
#self.channelsT ab = nuke.Tab_Knob ('channelsTab', 'channels')
#self.addKnob (self.channelsT ab)
#for i in range ( len ( self.channels ) ):
#exec "self.channel%s = ''" %( i )
#exec "self.channel%s = nuke.Boolean_Kn ob ('channel%s', '%s')" %( i, i, self.channels )
#exec "self.addKnob (self.channel%s )" %i
#exec "self.channel%s .setFlag(4096)" %i

##prefsTab
self.prefsTab = nuke.Tab_Knob ('prefsTab', 'preferences')
self.addKnob (self.prefsTab)

self.unPremult = nuke.Boolean_Kn ob ('unPremult', 'add unpremult / premult nodes')
self.addKnob (self.unPremult )
self.unPremult. setFlag (4096)

self.remove = nuke.Boolean_Kn ob ('remove', 'add remove node')
self.addKnob (self.remove)
self.remove.set Flag(4096)

self.grade = nuke.Boolean_Kn ob ('grade', 'add grade node')
self.addKnob (self.grade)
self.grade.setF lag(4096)

self.merge = nuke.Boolean_Kn ob ('merge', 'add merge node')
self.addKnob (self.merge)
self.merge.setF lag(4096)
self.operation = nuke.Enumeratio n_Knob ('operation', ' | operation', [ 'atop', 'average', 'color-burn', 'color-dodge', 'conjoint-over' , 'copy', 'difference', 'disjoint-over' , 'divide', 'exclusion', 'from', 'geometric', 'hard-light', 'hypot', 'in', 'mask', 'matte', 'max', 'min', 'minus', 'multiply', 'out', 'over', 'overlay', 'plus', 'screen', 'soft-light', 'stencil', 'under', 'xor'])
self.addKnob (self.operation )
self.operation. clearFlag(4096)
self.operation. setValue('plus' )

self.copyAlpha = nuke.Boolean_Kn ob ('copyAlpha', 'add copyAlpha node')
self.addKnob (self.copyAlpha )
self.copyAlpha. setFlag(4096)

self.noShuffLab el = nuke.Boolean_Kn ob ('noShuffLabel' , 'remove label from Shuffles')
self.addKnob (self.noShuffLab el)
self.noShuffLab el.setFlag(4096)

self.separation = nuke.Double_Kno b ('separation', 'separation between nodes')
self.addKnob (self.separatio n)
self.separation .setFlag(4096)
self.separation .setRange (100, 400)
self.separation .setDefaultValu e ([200])

self.shuffLayer sColor = nuke.ColorChip_ Knob ('shuffLayersCo lor', 'Shuffle color')
self.addKnob (self.shuffLayer sColor)
self.shuffLayer sColor.setDefaultValue([nuke.toNode('pr eferences')['NodeColour05Color'].value()])
self.shuffLayer sColor.setFlag(4096)

self.bdrop = nuke.Boolean_Kn ob ('bdrop', 'add backDrop')
self.addKnob (self.bdrop)
self.bdrop.setF lag(4096)

self.bdropColor = nuke.ColorChip_ Knob ('bdropColor', 'backDrop color')
self.addKnob (self.bdropColo r)
self.bdropColor .setDefaultValu e([926365441])

self.separation 01 = nuke.Text_Knob ('separation01' , '')
self.addKnob (self.separation 01)

self.EndTab = nuke.EndTabGrou p_Knob ('endTabGroup', '')
self.addKnob ( self.EndTab )

#self.importAll Channels = nuke.PyScript_K nob ('importAllChan nels', 'all channels', "print 'function to import all layers'")
#self.addKnob (self.importAll Channels)

def knobChanged(sel f, knob):
if knob == self.presets:
updateLayersPre set ()

def returnLayers(se lf):
return self.layers
def returnChannels( self):
return self.channels


def getData ():
#gets selected node or not
try:
global n
n = nuke.selectedNo de()
except:
nuke.message ('Select a node.')
return

#if all good launches the panel########## ############### ############### ############### #
layers = shuffleChannels (n).returnLayer s() #returns the layers list
channels = shuffleChannels (n).returnChann els() #returns the channels list
global p
p = shuffleChannels (n) #builds the panel
windowHeight = len(layers)*20+ 165 #changes panel dimensions
if windowHeight > 1000: #
windowHeight = 1000 #
p.setMinimumSiz e (600, windowHeight) #
readPrefsFile(p )
refreshPresetsM enu()
thePanel = p.showModalDial og() #launches the panel

if thePanel == False:
return
else:
pass


#beyond this point all happens after the panel has been closed#########################
#creation of the prefs variable
prefs = {'unPremult': p.unPremult.val ue(), 'remove': p.remove.value( ), 'grade': p.grade.value() , 'merge': p.merge.value() , 'operation': p.operation.val ue(), 'copyAlpha': p.copyAlpha.val ue(), 'noShuffLabel': p.noShuffLabel. value(), 'separation': p.separation.va lue(), 'shuffLayersCol or': p.shuffLayersCo lor.value(), 'bdrop': p.bdrop.value() , 'bdropColor': p.bdropColor.value()}
##writes the preferences file
writePrefsFile( p, str(prefs))
#here I collect what layers have been selected
layerList = []
for i in range (len ( layers ) ):
return_dict = {}
exec("gate = p.layer%s.value ()" %i, globals(), return_dict)
if return_dict['ga te'] == True :
layerList.appen d ( layers )

#here it will create a node tree if some layers have been selected
if len(layerList) > 0:
buildTree(layer List, prefs)
else:
return


def selectAll():
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec("(p.layer% s.setValue(True ))" %i)

def deselectAll():
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec("(p.layer% s.setValue(Fals e))" %i)


def buildTree(layer s, prefs):

nukePrefs = nuke.toNode('pr eferences')
defGoofyFootVal ue = nukePrefs['goof y_foot'].value( )
nukePrefs['goof y_foot'].setVal ue( 0 )
selNodeXPos = n.xpos()
selNodeYPos = n.ypos()

n['selected'].s etValue(False)

shuffDot0 = nuke.createNode ( 'Dot', 'selected False', False)
shuffDot0['xpos '].setValue(sel NodeXPos + 200)
shuffDot0YPos = int( selNodeYPos + 100 )
shuffDot0['ypos '].setValue( shuffDot0YPos )
shuffDot0.setIn put(0, n)

#creation of nodes
for i in range(len(layer s)):
#dots
newXPos = (prefs['separat ion']*(i+1))+sh uffDot0['xpos'] .value()
exec("shuffDot% s = nuke.createNode ('Dot', 'name shuffDot%s xpos %s ypos %s', inpanel=False)" %( i+1, i+1, newXPos , shuffDot0YPos ))
lastDot = i
exec("shuffDot% s['selected'].setValue(False)" %( len(layers) ))


##shuffles
for i in range(len(layer s)):
newXPos = (prefs['separat ion']*(i+1))+sh uffDot0['xpos'] .value()
shuf = nuke.createNode ( 'Shuffle', 'name %s in %s selected False xpos %s ypos %s' %( layers, layers, newXPos-34, shuffDot0YPos+5 0), False )
exec("shuf.setI nput(0, shuffDot%s)" %(i+1))
if i == 0:
shuf['xpos'].se tValue(newXPos- 34)
shuf['ypos'].se tValue(shuffDot 0YPos+50)
##color
if prefs['shuffLay ersColor'] != nuke.toNode('pr eferences')['NodeColour05Color'].value():
shuf['tile_color'].setValue(prefs['shuffLay ersColor'])
##label
if prefs['noShuffL abel'] == True:
shuf['label'].s etValue('')

#removes
if prefs['remove'] == True:
rem = nuke.createNode ('Remove', 'operation keep channels rgba selected False xpos %s ypos %s' %( newXPos-34, shuffDot0YPos+8 8 ), False )
rem.setInput(0, shuf)

#grades
if prefs['grade'] == True:
grad = nuke.createNode ('Grade', 'xpos %s ypos %s' %( newXPos-34, shuffDot0YPos+3 00 ), False)

#merges
if prefs['merge'] == True:
if i == 0:
dotMerge = nuke.createNode ('Dot', 'xpos %s ypos %s selected False' %( newXPos, shuffDot0YPos+5 04 ), False)
else:
exec("merge%s = nuke.createNode ('Merge', 'operation %s xpos %s ypos %s', False)" %( i, prefs['operatio n'], newXPos-34, shuffDot0YPos+5 00 ))
exec("nukescrip ts.swapAB(merge %s)" %i)
if i == 1 :
exec("merge%s.s etInput (0, dotMerge)" %i)
else:
exec("merge%s.s etInput (0, merge%s)" %( i, i-1))

#copyAlpha
if prefs['copyAlph a'] == True:
copyDot = nuke.createNode ('Dot', 'xpos %s ypos %s' % ( newXPos+prefs[' separation'], shuffDot0YPos ), False)
exec("copyDot.s etInput(0, shuffDot%s)" %(len(layers)))
copyNode = nuke.createNode ('Copy', 'xpos %s ypos %s' %( newXPos+prefs[' separation']-34 , shuffDot0YPos+4 94 ), False)
try:
exec("copyNode. setInput(0, merge%s)" %(len(layers)-1 ))
except:
pass
copyNode.setInp ut(1, copyDot)

#premult
if prefs['unPremul t'] == True:
unpr = nuke.createNode ('Unpremult', 'selected False xpos %s ypos %s channels all' %(shuffDot0.xpo s()+50, shuffDot0YPos-1 0), False)
unpr.setInput(0 , shuffDot0)
prem = nuke.createNode ('Premult', 'selected False xpos %s ypos %s channels all' %(newXPos+prefs[' separation']-34 , shuffDot0YPos+5 50), False)
prem['selected' ].setValue(Fals e)
if prefs['copyAlph a'] == True:
prem.setInput(0 , copyNode)
elif prefs['merge'] == True:
exec("prem.setInput(0 , merge%s)" %str(len(layers )-1))
exec("prem['xpo s'].setValue(me rge%s.xpos())" %str(len(layers )-1))
elif prefs['grade'] == True:
prem.setInput(0 , grad)
prem['xpos'].se tValue(grad.xpo s())
elif prefs['remove'] == True:
prem.setInput(0 , rem)
prem['xpos'].se tValue(rem.xpos ())
else:
prem.setInput(0 , shuf)
prem['xpos'].se tValue(shuf.xpo s())
shuffDot1.setIn put(0, unpr)

#backDrop
width = 0
height = 0
if prefs['bdrop'] == True:
width = ( prefs['separati on'] * (len(layers)+1) )
if prefs['unPremul t'] == True:
height = 750
elif prefs['copyAlph a'] == True:
height = 650
elif prefs['grade'] == True:
height = 500
elif prefs['merge'] == True:
height = 600
elif prefs['remove'] == True:
height = 300
else:
height = 250
if prefs['copyAlph a'] == True:
width = width + prefs['separati on']


bd = nuke.createNode ('BackdropNode', 'tile_color %s' %( prefs['bdropCol or'] ) , False)
bd['xpos'].setV alue( shuffDot0.xpos( ) - 100)
bd['ypos'].setV alue( shuffDot0.ypos( ) - 100)
bd['bdwidth'].s etValue( width )
bd['bdheight']. setValue( height )
#print 'width = %s , height = %s' %(width, height)

##resets prefs to user defined state
nukePrefs = nuke.toNode('pr eferences')
nukePrefs['goof y_foot'].setVal ue( defGoofyFootVal ue )



def readPrefsFile(p ): #reads the preferences file and sets the values on the panel knobs
try:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
except:
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("['prefs', {'none':['none' ], 'all': ['all']}]")
prefsFileW.clos e()
return
try:
prefs = eval(prefsFileR .read())[0]
for keys in prefs:
if keys != 'operation':
exec("p.%s.setV alue(%s)" %( keys, prefs[keys] ))
else:
exec("p.%s.setV alue('%s')" %( keys, prefs[keys] ))
except Exception as e:
pass
#print(traceback.format_exc(e))

def writePrefsFile( p, prefs):
try:
prefsFile = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFile. read())
prefsFile.close ()
prefsFile = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFile.write ("[%s, %s]" %(prefs, prefsFileConten t[1]))
except Exception as e:
pass
#print(traceback.format_exc(e))


def savePreset():
presetName = nuke.getInput(' name of preset')
if presetName == None or '':
return
presetLayers = []
layers = shuffleChannels (n).returnLayer s()
for i in range (len(layers)):
exec(("selected = p.layer%s.value ()") %i)
if selected == True:
presetLayers.ap pend (layers)
preset = {}
preset [presetName] = presetLayers
# print 'and the preset is: %s' %preset

prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
presetsInFile [presetName] = presetLayers
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("[%s, %s]" %(prefsFileConten t[0], presetsInFile))
prefsFileW.clos e()
refreshPresetsM enu()
p.presets.setVa lue( presetName )

def deletePreset():
if p.presets.value () not in ['all', 'none']:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
if p.presets.value () not in ['all', 'none']:
del presetsInFile [ p.presets.value () ]
prefsFileW = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'w')
prefsFileW.writ e ("[%s, %s]" %(prefsFileConten t[0], presetsInFile))
prefsFileW.clos e()

p.presets.setVa lue('none')

refreshPresetsM enu()



def refreshPresetsM enu():
try:
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]
list = sorted(presetsI nFile.keys())
list.remove ('all')
list.remove('no ne')
list.insert (0, 'all')
list.insert (0, 'none')
p.presets.setVa lues( list )
except Exception as e:
pass
#print(traceback.format_exc(e))

def updateLayersPre set ():
prefsFileR = open('C:/Users/ %s/.nuke/shuffl ePanelPrefs.txt ' % getpass.getuser (), 'r')
prefsFileConten t = eval(prefsFileR .read())
presetsInFile = prefsFileConten t[1]

deselectAll()

chosenPreset = p.presets.value ()

layersInPreset = presetsInFile [ p.presets.value () ]

layers = shuffleChannels (n).returnLayer s()

if p.presets.value () not in ['all', 'none']:
for i in range (len(layers)):
#exec "(p.layer%s.set Value(True))" %i
exec("lay = (p.layer%s.labe l())" %i)
if lay in layersInPreset :
exec("(p.layer% s.setValue(True ))" %i)
elif p.presets.value () == 'all':
selectAll()
else:
deselectAll()
 

You have no rights to post comments

We have 2125 guests and 39 members online