richbobo

Nuke Threading Example with Python Panel

Apr 25th, 2014
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import nuke
  2. import nukescripts
  3. import threading
  4.  
  5.  
  6. class renderWrites(threading.Thread):
  7.    
  8.     def __init__(self, writenode):
  9.         # Start threading...
  10.         threading.Thread.__init__(self)
  11.         # Get the currently selected Write node from the dropdown knob...
  12.         self.writeNode = nuke.toNode(writenode)
  13.    
  14.     def run(self):
  15.         try:
  16.             nuke.executeInMainThread(nuke.execute, args=self.writeNode, kwargs={'continueOnError':True} )
  17.         except Exception as e:
  18.             print "ERROR: %s" % e
  19.        
  20.        
  21. class RenderWritesPanel(nukescripts.PythonPanel):
  22.  
  23.     def __init__(self):
  24.        
  25.         self.write_nodes = []
  26.         for n in nuke.allNodes():
  27.             if n.Class() == 'Write':
  28.                 name = n.name()
  29.                 self.write_nodes.append(name)
  30.                
  31.         nukescripts.PythonPanel.__init__(self, "Render Writes Panel")
  32.         self.writes = nuke.Enumeration_Knob("writes", "writes", self.write_nodes)
  33.         self.render = nuke.PyScript_Knob("render", "render")
  34.         for i in [self.writes, self.render]:
  35.             self.addKnob(i)
  36.            
  37.     def knobChanged(self, knob):
  38.         if knob is self.render:
  39.             t = renderWrites(self.writes.value())
  40.             t.start()
  41.            
  42.                  
  43. RenderWritesPanel().show()
Advertisement
Add Comment
Please, Sign In to add comment