Advertisement
Totheroo

Nuke - Write Node Panel (Nuke 14)

Oct 1st, 2024 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.53 KB | Source Code | 0 0
  1. #   Write Node Switch Panel v11.0
  2. #   Written by EToth / JCollier
  3. #   Updated 10/20/2016
  4.  
  5. import sys
  6. import nuke # JC: added this so it doesn't just fail to init
  7. from functools import partial
  8. from PySide2.QtGui import *
  9. from PySide2.QtCore import *
  10.  
  11. #Function to clean up the filepath string,
  12. #should return just the file and extension
  13. def filePath(FilePath):
  14.     FilePath=FilePath.split("/")
  15.     FilePath=FilePath[-1]
  16.     FilePath=FilePath.replace(".%04d","")
  17.     return FilePath
  18.  
  19. #Function to disable all Write Nodes
  20. def disableAll():
  21.     for node in nuke.allNodes("Write"):
  22.         node['disable'].setValue(True)
  23.     for node in nuke.allNodes("WriteTank"):
  24.         node['disable'].setValue(True)
  25.     for node in nuke.allNodes("WriteGeo"):
  26.         node['disable'].setValue(True)
  27.  
  28. #Function to enable all Write Nodes
  29. def enableAll():
  30.     for node in nuke.allNodes("Write"):
  31.         node['disable'].setValue(False)
  32.     for node in nuke.allNodes("WriteTank"):
  33.         node['disable'].setValue(False)
  34.     for node in nuke.allNodes("WriteGeo"):
  35.         node['disable'].setValue(False)
  36.  
  37. #Function to restore Write nodes to what they were when the panel was first opened.
  38. def currentStatus(nodeList,self):
  39.     #print 'nodeList: {}'.format(str(nodeList))
  40.     #checkboxes = []
  41.     for node in range(0,len(nodeList)):
  42.         nuke.toNode(nodeList[node][0])['disable'].setValue(nodeList[node][2])
  43.         temp = nodeList[node][0]
  44.         #print temp, nodeList[node][2]
  45.         if nodeList[node][2] == True:
  46.             exec("self.checkbox_"+temp+".setChecked(False)")
  47.             #print nodeList[node][0], "TRUE"
  48.         else:
  49.             exec("self.checkbox_"+temp+".setChecked(True)")
  50.             #print nodeList[node][0], "FALSE"
  51.  
  52. #Function to select all write nodes (Shotgun nodes included)
  53. def selectAll():
  54.     for node in nuke.allNodes("Write"):
  55.         node['selected'].setValue(True)
  56.     for node in nuke.allNodes("WriteTank"):
  57.         node['selected'].setValue(True)
  58.     for node in nuke.allNodes("WriteGeo"):
  59.         node['selected'].setValue(True)
  60.  
  61. #Function to select all Shotgun Write nodes
  62. def selectSG():
  63.     for node in nuke.allNodes():
  64.         node['selected'].setValue(False)
  65.     for node in nuke.allNodes("WriteTank"):
  66.         node['selected'].setValue(True)
  67.  
  68. #Function to select all non-SG Write nodes
  69. def selectWrite():
  70.     for node in nuke.allNodes():
  71.         node['selected'].setValue(False)
  72.     for node in nuke.allNodes("Write"):
  73.         node['selected'].setValue(True)
  74.  
  75. #Function to select nothing
  76. def selectNone():
  77.     for node in nuke.allNodes():
  78.         node['selected'].setValue(False)
  79.  
  80. #Function to return a list of all Write, WriteGeo, SGTK Write Nodes
  81. #as a list of nodes wih their attributes inside
  82. def nodeList():
  83.     NodeList=[]
  84.     #find all Write Nodes and append to NodeList
  85.     for node in nuke.allNodes('Write'):
  86.         nodeInfo=[]
  87.         nodeInfo.append(node['name'].getValue())
  88.         nodeInfo.append(filePath(node['file'].getValue()))
  89.         nodeInfo.append(node['disable'].value())
  90.         nodeInfo.append(node.Class())
  91.         NodeList.append(nodeInfo)
  92.     #find all WriteGeo Nodes and append to NodeList
  93.     for node in nuke.allNodes('WriteGeo'):
  94.         nodeInfo=[]
  95.         nodeInfo.append(node['name'].getValue())
  96.         nodeInfo.append(filePath(node['file'].getValue()))
  97.         nodeInfo.append(node['disable'].value())
  98.         nodeInfo.append(node.Class())
  99.         NodeList.append(nodeInfo)
  100.     #find all WriteGeo Nodes and append to NodeList
  101.     for node in nuke.allNodes('WriteTank'):
  102.         nodeInfo=[]
  103.         nodeInfo.append(node['name'].getValue())
  104.         nodeInfo.append(node['path_filename'].value().replace(".%04d",""))
  105.         nodeInfo.append(node['disable'].value())
  106.         nodeInfo.append(node.Class())
  107.         NodeList.append(nodeInfo)
  108.     NodeList.sort(key=lambda x: x[0])
  109.     #print NodeList
  110.     return NodeList
  111.  
  112. #Function to open help
  113. def selfHelp():
  114.     print("Opening writeNodeSwitch help...")
  115.     # the Qt for this would be:
  116.     # helpURL = "https://mammal.atlassian.net/wiki/display/MC/Write+Nodes+Switch+Panel"
  117.     # QtGui.QDesktopServices.openUrl(QtCore.QUrl(helpURL))
  118.     nuke.tcl("start https://mammal.atlassian.net/wiki/display/MC/Write+Nodes+Switch+Panel")
  119.  
  120. class Panel(QWidget):
  121.     def __init__(self):
  122.         #Check allWidgets to see if "Panel" already exists, if it does, SHUT IT DOWN!
  123.         for entry in QApplication.allWidgets():
  124.             if type(entry).__name__ == 'Panel':
  125.                 entry.close()
  126.                
  127.         super(Panel, self).__init__()
  128.  
  129.         #name the panel
  130.         self.setWindowTitle("Write Node Switch Panel")
  131.  
  132.         #maximize
  133.         #self.showMaximized()
  134.         self.setGeometry(375,100,1,1)
  135.  
  136.         #get the nodeList
  137.         self.NodeList = nodeList()
  138.         layoutMaster = QHBoxLayout()
  139.  
  140.         layoutGroupWriteNodes = QVBoxLayout()
  141.         groupWriteNodes = QGroupBox("Nuke Write Nodes")
  142.         groupWriteNodes.setStyleSheet("QGroupBox {font-size: 12pt; font-weight:Bold}")
  143.         layoutSGTKWriteNodes = QVBoxLayout()
  144.         groupSGTKNodes = QGroupBox("Shotgun Write Nodes")
  145.         groupSGTKNodes.setStyleSheet("QGroupBox {font-size: 12pt; font-weight:Bold}")
  146.         layoutWriteGeoNodes = QVBoxLayout()
  147.         groupWriteGeoNodes = QGroupBox("Write Geo Nodes")
  148.         groupWriteGeoNodes.setStyleSheet("QGroupBox {font-size: 12pt; font-weight:Bold}")
  149.  
  150.         for i in range(0,len(self.NodeList)):
  151.             nodeName='self.checkbox_'+str(self.NodeList[i][0])
  152.             exec(nodeName+"=QCheckBox(self.NodeList[i][0])")
  153.             exec(nodeName+".setText(self.NodeList[i][0]+str(' : ')+self.NodeList[i][1])")
  154.             exec(nodeName+".setChecked(1-self.NodeList[i][2])")  # set the checkbox True/False
  155.             exec(nodeName+".setToolTip(self.NodeList[i][0]+str(' : ')+self.NodeList[i][1])")
  156.             exec(nodeName+".clicked.connect(self.who_clicked)")
  157.             nodeName=str("self.checkbox_"+self.NodeList[i][0])
  158.             if self.NodeList[i][3] == "Write":
  159.                 layoutGroupWriteNodes.addWidget(eval(nodeName))
  160.             if self.NodeList[i][3] == "WriteTank":
  161.                 layoutSGTKWriteNodes.addWidget(eval(nodeName))
  162.             if self.NodeList[i][3] == "WriteGeo":
  163.                 layoutWriteGeoNodes.addWidget(eval(nodeName))
  164.  
  165.         #addStretch to push buttons together
  166.         #(otherwise they stretch to fit the vertical limit)
  167.         layoutGroupWriteNodes.addStretch()
  168.         layoutSGTKWriteNodes.addStretch()
  169.         layoutWriteGeoNodes.addStretch()
  170.  
  171.         groupWriteNodes.setLayout(layoutGroupWriteNodes)
  172.         groupSGTKNodes.setLayout(layoutSGTKWriteNodes)
  173.         groupWriteGeoNodes.setLayout(layoutWriteGeoNodes)
  174.  
  175.         layoutMaster.addWidget(groupWriteNodes)
  176.         layoutMaster.addWidget(groupSGTKNodes)
  177.         layoutMaster.addWidget(groupWriteGeoNodes)
  178.  
  179.         layoutButtons = QVBoxLayout()
  180.         groupButtons = QGroupBox("Buttons")
  181.         #Enable All Write Nodes
  182.         enableAllButton = QPushButton("Enable All")
  183.         enableAllButton.clicked.connect(enableAll)
  184.         enableAllButton.clicked.connect(self.enableDisable)
  185.         enableAllButton.setStyleSheet("background-color: DarkGreen; font-weight: bold;  font-size: 14pt")
  186.         enableAllButton.setMinimumHeight(60)
  187.         #Disable All Write Nodes
  188.         disableAllButton = QPushButton("Disable All")
  189.         disableAllButton.clicked.connect(disableAll)
  190.         disableAllButton.clicked.connect(self.enableDisable)
  191.         disableAllButton.setStyleSheet("background-color:  DarkRed; font-weight: bold;  font-size: 14pt")
  192.         disableAllButton.setMinimumHeight(60)
  193.         disableAllButton.setMinimumWidth(200)
  194.         #Restore Write Nodes To Current Status
  195.         currentStatusButton = QPushButton("Current Status")
  196.         currentStatusButton.clicked.connect(partial(currentStatus, self.NodeList, self))
  197.         currentStatusButton.setStyleSheet("background-color: DarkGoldenRod; font-weight: bold;  font-size: 14pt")
  198.         currentStatusButton.setMinimumHeight(60)
  199.         #Select All Write Nodes (Shotgun nodes included)
  200.         selectAllButton = QPushButton("Select All")
  201.         selectAllButton.clicked.connect(selectAll)
  202.         selectAllButton.setMinimumHeight(40)
  203.         #Select All Shotgun Write Nodes
  204.         selectSGButton = QPushButton("Select Shotgun\nNodes")
  205.         selectSGButton.clicked.connect(selectSG)
  206.         selectSGButton.setMinimumHeight(40)
  207.         #Select Nuke Write Nodes
  208.         selectWriteButton = QPushButton("Select Nuke\nNodes")
  209.         selectWriteButton.clicked.connect(selectWrite)
  210.         selectWriteButton.setMinimumHeight(40)
  211.         #Select Nothing
  212.         selectNoneButton = QPushButton("Select None")
  213.         selectNoneButton.clicked.connect(selectNone)
  214.         selectNoneButton.setMinimumHeight(40)
  215.         #Horizontal Lines
  216.         line1 = QFrame()
  217.         line1.setFrameShape(QFrame.HLine)
  218.         line1.setFrameShadow(QFrame.Sunken)
  219.         line2 = QFrame()
  220.         line2.setFrameShape(QFrame.HLine)
  221.         line2.setFrameShadow(QFrame.Sunken)
  222.         line3 = QFrame()
  223.         line3.setFrameShape(QFrame.HLine)
  224.         line3.setFrameShadow(QFrame.Sunken)
  225.  
  226.         #Close the panel
  227.         closeButton = QPushButton("Close")
  228.         closeButton.clicked.connect(self.closePanel)
  229.         closeButton.setMinimumHeight(60)
  230.         closeButton.setStyleSheet("font-weight: bold;  font-size: 14pt")
  231.  
  232.         #Help Button
  233.         selfHelpButton = QPushButton("Help")
  234.         selfHelpButton.clicked.connect(selfHelp)
  235.         selfHelpButton.setMinimumHeight(40)
  236.  
  237.         #Layout the buttons across the UI
  238.         layoutButtons.addWidget(enableAllButton)
  239.         layoutButtons.addWidget(disableAllButton)
  240.         layoutButtons.addWidget(currentStatusButton)
  241.         layoutButtons.addWidget(line1)
  242.         layoutButtons.addWidget(selectAllButton)
  243.         layoutButtons.addWidget(selectSGButton)
  244.         layoutButtons.addWidget(selectWriteButton)
  245.         layoutButtons.addWidget(selectNoneButton)
  246.         layoutButtons.addStretch()
  247.         layoutButtons.addWidget(line2)
  248.         layoutButtons.addWidget(selfHelpButton)
  249.         layoutButtons.addWidget(line3)
  250.         layoutButtons.addStretch()
  251.         layoutButtons.addWidget(closeButton)
  252.         groupButtons.setLayout(layoutButtons)
  253.  
  254.  
  255.         layoutMaster.addWidget(groupButtons)
  256.  
  257.         self.setLayout(layoutMaster)
  258.  
  259.     #Function to close the panel
  260.     # JC: I moved this into your widget class
  261.     # because it was incorrectly scoped
  262.     # I also fixed the corresponding connector for the
  263.     # close button to call "self.closePanel"
  264.     def closePanel(self):
  265.         self.close()
  266.  
  267.     #Function to close if ESC key is pressed
  268.     def keyPressEvent(self, e):
  269.         if e.key() == Qt.Key_Escape:
  270.             self.close()
  271.  
  272.     #Function to check enable/disable in the UI Panel
  273.     def who_clicked(self):
  274.         sender = self.sender()
  275.         senderText = self.sender().text()
  276.         buttons=[]
  277.         for button in range(0,len(self.NodeList)):
  278.             buttons.append(self.NodeList[button][0]+' : '+self.NodeList[button][1])
  279.         x=0
  280.         for i in buttons:
  281.             if i == senderText:
  282.                 onOff=nuke.toNode(self.NodeList[x][0])
  283.                 if onOff['disable'].value() == True:
  284.                     onOff['disable'].setValue(False)
  285.                     print(self.NodeList[x][0:2], "ENABLED")
  286.                 else:
  287.                     onOff['disable'].setValue(True)
  288.                     print(self.NodeList[x][0:2], "DISABLED")
  289.             x+=1
  290.  
  291.     #Function to check all the checkboxes on/off depending on
  292.     #user input of ENABLE/DISABLE ALL
  293.     def enableDisable(self):
  294.         sender=self.sender()
  295.         senderText=self.sender().text()
  296.         #print senderText
  297.         checkboxes = []
  298.         for checkbox in range(0,len(self.NodeList)):
  299.             checkboxes.append(self.NodeList[checkbox][0])
  300.         if senderText == "Enable All":
  301.             for temp in checkboxes:
  302.                 #print temp
  303.                 exec("self.checkbox_"+temp+".setChecked(True)")
  304.         elif senderText == "Disable All":
  305.             for temp in checkboxes:
  306.                 exec("self.checkbox_"+temp+".setChecked(False)")
  307.  
  308. '''
  309. def main(): # JC: we call things as <filename>.main() in menu.py
  310.    # init the Panel instance
  311.    # then show the panel
  312.    panel = Panel()
  313.    panel.show()
  314.  
  315. if __name__ == "__main__":
  316.    main()
  317. '''
  318. # ET: In the absence of menu.py; Let's just run this in the script editor for now...
  319. panel = Panel()
  320. panel.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement