Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.9 kB
1
Indexable
Never
'''
ShuffleControl v1.0 by Jorrit Schulte

Add this to menu.py:
toolbar = nuke.toolbar("Nodes")
toolsMenu = toolbar.addMenu("Tools")
toolsMenu.addCommand("ShuffleControl", "nuke.load('ShuffleControl')")
'''

try:
    from PySide.QtGui import *
    from PySide.QtCore import *
except ImportError:
    from PySide2.QtWidgets import *
    from PySide2.QtCore import *
    from PySide2.QtGui import *

from ShuffleControl_interface import Ui_MainWindow

#checks if there is a node selected before opening the ui
showWindow = True
try:
	node = nuke.selectedNode()
	channels = node.channels()
	channels = list( set([channel.split('.')[0] for channel in channels]) )
	channels.sort()
except:
	showWindow = False
	nuke.message('No node selected')


class Panel(QMainWindow, Ui_MainWindow):
	def __init__(self):
		super(Panel, self).__init__()
		self.setupUi(self)
		self.center()

		for channel in channels:
			if channel != 'rgba':
				self.inList.addItem(channel)

		self.shuffleButton.clicked.connect(self.preRun)
		self.close

	#checks if there is at least one channel selected
	def preRun(self):
		if self.outList.count() > 0:
			self.run()
			self.close()
		else:
			self.close()
			nuke.message('no channels were chosen.')

	def run(self):
		undo = nuke.Undo()
		undo.begin("ShuffleControl")

		out = []
		x = self.horizontalSpacing.value()
		y = self.verticalSpacing.value()

		latestDot = node
		latestMerge = ''
		count = self.outList.count()
		for index in range(count):
			channelName = str( self.outList.item(index).text() )
			out.append(channelName)
			#build dot node
			dot = nuke.nodes.Dot()
			dot.setInput(0, latestDot)
			if latestMerge == '':
				dot['xpos'].setValue(latestDot.xpos()+node.screenWidth()/2 - 6)
				dot['ypos'].setValue(latestDot.ypos()+200)
			else:
				dot['xpos'].setValue(latestDot.xpos()+x)
				dot['ypos'].setValue(latestDot.ypos())
			dot['label'].setValue(channelName)
			dot['note_font_size'].setValue(50)

			#build shuffle node
			shuffle = nuke.nodes.Shuffle()
			shuffle.setInput(0, dot)
			shuffle['in'].setValue(channelName)
			shuffle['alpha'].setValue(0)
			shuffle['postage_stamp'].setValue(True)
			shuffle['xpos'].setValue(dot.xpos()-34)
			shuffle['ypos'].setValue(dot.ypos()+18)

			#build merge node
			if latestMerge == '':
				merge = nuke.nodes.Dot()
				merge['xpos'].setValue(dot.xpos())
				merge['ypos'].setValue(shuffle.ypos()+y+4)
				merge.setInput(0, shuffle)
			else:
				merge = nuke.nodes.Merge2()
				merge.setInput(0, latestMerge)
				merge.setInput(1, shuffle)
				merge['xpos'].setValue(dot.xpos() - merge.screenWidth()/2 + 6)
				merge['ypos'].setValue(shuffle.ypos()+y)
				merge['operation'].setValue('plus')

			#redefine latest nodes
			latestDot = dot
			latestMerge = merge

		#create Expression node
		if self.expressionNodeBox.isChecked() == True:
			#expression dot node
			Xdot = nuke.nodes.Dot()
			Xdot.setInput(0, latestDot)
			Xdot['xpos'].setValue(latestDot.xpos()+x)
			Xdot['ypos'].setValue(latestDot.ypos())
			Xdot['label'].setValue('difference')
			Xdot['note_font_size'].setValue(50)

			#write expression
			r = 'red'
			g = 'green'
			b = 'blue'
			for i in out:
				r += ' - ' + i + '.red'
				g += ' - ' + i + '.green'
				b += ' - ' + i + '.blue'

			#buid expression node
			expression = nuke.nodes.Expression()
			expression.setInput(0, Xdot)
			expression['expr0'].setValue(r)
			expression['expr1'].setValue(g)
			expression['expr2'].setValue(b)
			expression['expr3'].setValue('0')
			expression['postage_stamp'].setValue(True)
			expression['xpos'].setValue(Xdot.xpos()-34)
			expression['ypos'].setValue(Xdot.ypos()+18)

			merge = nuke.nodes.Merge2()
			merge.setInput(0, latestMerge)
			merge.setInput(1, expression)
			merge['xpos'].setValue(Xdot.xpos() - merge.screenWidth()/2 + 6)
			merge['ypos'].setValue(shuffle.ypos()+y)
			merge['operation'].setValue('plus')

			latestDot = Xdot
			latestMerge = merge

		#create Copy Alpha node
		if self.alphaBox.isChecked() == True:
			#alpha dot node
			Adot = nuke.nodes.Dot()
			Adot.setInput(0, latestDot)
			Adot['xpos'].setValue(latestDot.xpos()+x)
			Adot['ypos'].setValue(latestDot.ypos())
			Adot['label'].setValue('alpha')
			Adot['note_font_size'].setValue(50)
			#build Copy node
			copy = nuke.nodes.Copy()
			copy.setInput(0, latestMerge)
			copy.setInput(1, Adot)
			copy['xpos'].setValue(Adot.xpos() - copy.screenWidth()/2 + 6)
			copy['ypos'].setValue(latestMerge.ypos() - 6)
			copy['from0'].setValue('rgba.alpha')
			copy['to0'].setValue('rgba.alpha')

		undo.end()

	#Center widget to correct screen
	def center(self):
		frameGm = self.frameGeometry()
		screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
		centerPoint = QApplication.desktop().screenGeometry(screen).center()
		frameGm.moveCenter(centerPoint)
		self.move(frameGm.topLeft())

if showWindow:
	panel = Panel()
	panel.show()