Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sceneControl.py 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943
  1. from __future__ import print_function
  2. import os
  3. import os.path
  4. from os.path import abspath
  5. import nuke
  6. import KEnv
  7. import re
  8. from imp import reload
  9. from collections import OrderedDict
  10. # import ftrack_tools -> in getframerange(node)
  11. # martin@keller.io
  12. __version__ = '1.2'
  13. # default interface values
  14. projectDef = 'GEN'
  15. seasonDef = '01'
  16. episodeDef = '101'
  17. listTasks = ['taskOne___', 'taskTwo___']
  18. listDepts = ['departmentOne___', 'departmentTwo___']
  19. seqDef = '001'
  20. shotDef = '010'
  21. major_version = 1
  22. minor_version = 1
  23. user = 'xy'
  24. info = ''
  25. start = 1001
  26. cutIn = 1001
  27. cutOut = 1001
  28. end = 1001
  29. comment = ''
  30. # / default interface values
  31. # debug
  32. # __GLOBALS__
  33. # generic project folder: //hades/p/_projekte/GENFOLDER
  34. GENFOLDER = 'GEN'
  35. INIT_DONE = False
  36. DEBUG = True
  37. UPDATE_TOOLSET = False
  38. WRITENODE_VERSION = 1.0
  39. USE_ENV_PROJECT_ROOT = 1
  40. WRITENODE_LABEL = '[value compression]'
  41. # Plugin / commands
  42. class sceneControl(KellerNukePlugin):
  43. def configurePlugin(self):
  44. self.menu = nuke.menu('Nuke')
  45. m = self.menu.addMenu('SceneControl')
  46. m.addCommand('SceneControl', 'import sceneControl; sceneControl.createSceneControl()',shortcut='F12')
  47. m.addCommand('Increment Major', 'import sceneControl; sceneControl.increment_major_version()', tooltip="Increment Major version and save script.", shortcut='alt+shift+s')
  48. m.addCommand('Increment Minor', 'import sceneControl; sceneControl.increment_minor_version()', tooltip="Increment Minor version and save script.", shortcut='alt+s')
  49. m.addCommand('Reload Config', 'import sceneControl; sceneControl.kenvDelete()')
  50. m.addCommand('Helpers/Read/Set Missing Frames Mode', 'import sceneControl; sceneControl.setErrorMode()', tooltip="Sets the Error Mode on selected Read nodes.")
  51. m.addCommand('Helpers/Read/Set colorspace on Nodes', 'import sceneControl; sceneControl.setOcioRole()', tooltip="Sets the OCIO role on selected Read / Write nodes.")
  52. m.addCommand('Helpers/Read/Reload Reads', 'import sceneControl; sceneControl.refresh_read_nodes()', tooltip="Reload footage of selected Read / Write nodes.")
  53. #
  54. m.addCommand('Helpers/Write/Ignore selected Nodes', 'import sceneControl; sceneControl.setIgnoreFlag(True)')
  55. m.addCommand('Helpers/Write/Manage selected Nodes','import sceneControl; sceneControl.setIgnoreFlag(False)')
  56. m.addCommand('Helpers/Write/Set colorspace on Nodes', 'import sceneControl; sceneControl.setOcioRole()', tooltip="Sets the OCIO role on selected Read / Write nodes.")
  57. m.addCommand('Helpers/Write/Update Write Nodes Tab', 'import sceneControl; sceneControl.updateWriteNodeConfig()', tooltip="Updates Keller Tab and functions of selected write nodes.")
  58. #internal
  59. m.addCommand('Debug/Enable Debug Mode', 'import sceneControl; sceneControl.setDebug(True)')
  60. m.addCommand('Debug/Disable Debug Mode', 'import sceneControl; sceneControl.setDebug(False)')
  61. m.addCommand('Debug/DeleteKEnv', 'import sceneControl; sceneControl.kenvDelete()')
  62. m.addCommand('Debug/Internal/ReloadTasks', 'import sceneControl; sceneControl.kenvReloadTasks()', index=10)
  63. #m.addCommand('Debug/Internal/GetRenderpath', 'import sceneControl; sceneControl.kenvGetRenderpath(task,element)', index=11)
  64. #m.addCommand('Debug/Internal/GetPreviewOutput', 'import sceneControl; sceneControl.kenvGetPreviewOutput()', index=12)
  65. m.addCommand('Debug/Internal/WriteNodeSetPath', 'import sceneControl; sceneControl.kenvWriteSetPath(writeNode)', index=13)
  66. m.addCommand('Debug/Internal/WriteNodeReloadTasks', 'import sceneControl; sceneControl.kenvWriteReloadTasks(writeNode)', index=14)
  67. m.addCommand('Debug/Internal/KEnvQuery', 'import sceneControl; sceneControl.kenvQuery(query,**kwargs)', index=15)
  68. # TODO: remove the commands from the menu
  69. #m.findItem('Draw/ReloadTasks').setVisible(False)
  70. #m.findItem('Draw/GetRenderpath').setVisible(False)
  71. #m.findItem('Draw/WriteNodeSetPath').setVisible(False)
  72. #m.findItem('Draw/WriteNodeReloadTasks').setVisible(False)
  73. #
  74. nuke.addOnCreate(onCreateWrite, nodeClass=('Write'))
  75. nuke.addOnScriptLoad(onScriptLoad)
  76. nuke.addKnobChanged(onKnobChanged)
  77. nuke.addOnDestroy(onDestroy)
  78. def unconfigurePlugin(self):
  79. self.menu.removeItem('SceneControl')
  80. self.menu.removeItem('Increment Major')
  81. self.menu.removeItem('Increment Minor')
  82. self.menu.removeItem('Reload Config')
  83. self.menu.removeItem('Helpers/Read/Set Missing Frames Mode')
  84. self.menu.removeItem('Helpers/Read/Set colorspace on Nodes')
  85. self.menu.removeItem('Helpers/Read/Reload Reads')
  86. self.menu.removeItem('Helpers/Write/Ignore selected Nodes')
  87. self.menu.removeItem('Helpers/Write/Manage selected Nodes')
  88. self.menu.removeItem('Helpers/Write/Set colorspace on Nodes')
  89. self.menu.removeItem('Helpers/Write/Update Write Nodes Tab')
  90. #
  91. self.menu.removeItem('Debug/Enable Debug Mode')
  92. self.menu.removeItem('Debug/Disable Debug Mode')
  93. self.menu.removeItem('Debug/DeleteKEnv')
  94. self.menu.removeItem('Debug/Internal/ReloadTasks')
  95. #self.menu.removeItem('Debug/Internal/GetRenderpath')
  96. #self.menu.removeItem('Debug/Internal/GetPreviewOutput')
  97. self.menu.removeItem('Debug/Internal/WriteNodeSetPath')
  98. self.menu.removeItem('Debug/Internal/WriteNodeReloadTasks')
  99. self.menu.removeItem('Debug/Internal/KEnvQuery')
  100. #
  101. nuke.removeOnCreate(onCreateWrite)
  102. nuke.removeOnScriptLoad(onScriptLoad)
  103. nuke.removeKnobChanged(onKnobChanged)
  104. nuke.removeOnDestroy(onDestroy)
  105. # EVENTS
  106. def onScriptLoad():
  107. sc = getSceneControl()
  108. if sc is None:
  109. createSceneControl()
  110. else:
  111. # SceneControl in script
  112. if kenvModuleLoaded():
  113. print('SceneControl: Info. Script Load. Generating KEnv environment...')
  114. initSceneControlValues(sc)
  115. def onKnobChanged():
  116. # sceneControl ready
  117. global INIT_DONE
  118. if not INIT_DONE:
  119. # not ready
  120. return
  121. k = nuke.thisKnob()
  122. refresh = ['project','dept','task','element','sequence','shot','major_version','minor_version','info','user','useEnvProjectRoot']
  123. task_refresh = ['dept','task']
  124. exr_compression = ['compression',]
  125. if k.name() in task_refresh:
  126. print('SceneControl: Info. Event task_refresh triggered.')
  127. # Department changed, loading new tasks
  128. kenvReloadTasks()
  129. if k.name() in refresh:
  130. print('SceneControl: Info. Event refresh triggered.')
  131. # Config changed, loading new tasks
  132. kenvGetWorkFile()
  133. pass
  134. # exr compression on write nodes
  135. if k.name() in exr_compression:
  136. # get the node
  137. n = nuke.thisNode()
  138. if k.value().startswith('Zip'):
  139. # % (r * 255, g * 255, b * 255, 1), 16): change r g and b to your liking
  140. hexColour = int('%02x%02x%02x%02x' % (184, 184, 0, 1), 16)
  141. n['tile_color'].setValue(hexColour)
  142. if k.value().startswith('DW'):
  143. # % (r * 255, g * 255, b * 255, 1), 16): change r g and b to your liking
  144. hexColour = int('%02x%02x%02x%02x' % (1 * 255, 0.666 * 255, 0.266 * 255, 1), 16)
  145. n['tile_color'].setValue(hexColour)
  146. def onCreateWrite():
  147. n = nuke.thisNode()
  148. createCustomWrite(n)
  149. return
  150. def onDestroy():
  151. print('SceneControl: Info. Nice meeting you. Removing Kenv now...')
  152. try:
  153. del(nuke.kenv)
  154. except:
  155. print('SceneControl: Info. KEnv was already gone.')
  156. # SceneControl
  157. def getSceneControl():
  158. c = nuke.exists("sceneCtrl")
  159. if c:
  160. sc = nuke.toNode('sceneCtrl')
  161. else:
  162. print('SceneControl: Error. No SceneControl node found. Creating one for you.')
  163. import sceneControl
  164. deselectAll()
  165. sceneControl.createSceneControl()
  166. sc = nuke.toNode('sceneCtrl')
  167. return sc
  168. def createSceneControl():
  169. # deselect all nodes
  170. deselectAll()
  171. # createUI
  172. print('SceneControl: Info. Creating SceneControl at Nuke root level.')
  173. #with nuke.root():
  174. # for calling from within groups
  175. try:
  176. nuke.thisParent().begin()
  177. except:
  178. pass
  179. scenecontrol = createSceneControlUI()
  180. # fill out
  181. kenvLoaded = kenvModuleLoaded()
  182. if kenvLoaded is not None:
  183. initSceneControlValues(scenecontrol)
  184. pass
  185. else:
  186. pass
  187. sc = nuke.toNode('sceneCtrl')
  188. # Init done. Callbacks now armed.
  189. global INIT_DONE
  190. INIT_DONE = True
  191. # touch
  192. sc.knobs()['major_version'].setValue(0)
  193. sc.knobs()['major_version'].setValue(1)
  194. try:
  195. nuke.thisParent().end()
  196. except:
  197. pass
  198. return sc
  199. def createSceneControlUI():
  200. n = nuke.Node("NoOp")
  201. n.setName("sceneCtrl")
  202. n['hide_input'].setValue(True)
  203. # % (r * 255, g * 255, b * 255, 1), 16): change r g and b to your liking
  204. hexColour = int('%02x%02x%02x%02x' % (0.2 * 255, 0.478 * 255, 0.647 * 255, 1), 16)
  205. n['tile_color'].setValue(hexColour)
  206. n['label'].setValue("_\n__")
  207. # ###########################
  208. # ---------------------------
  209. # tab main
  210. # ---------------------------
  211. # ###########################
  212. k = nuke.Tab_Knob('main', 'Main')
  213. n.addKnob(k)
  214. # Scriptname
  215. #k = nuke.String_Knob("scriptname", "Script")
  216. #n.addKnob(k)
  217. #n.knob("scriptname").setValue(scriptname)
  218. #n.knob("scriptname").setEnabled(False)
  219. # Project
  220. k = nuke.String_Knob('project', 'Project')
  221. k.setTooltip('Project Shortname')
  222. n.addKnob(k)
  223. n.knob('project').setValue(projectDef)
  224. n.knob('project').setFlag(nuke.STARTLINE)
  225. # Department
  226. k = nuke.Enumeration_Knob('dept', 'Dept', listDepts)
  227. k.setTooltip('Department. Changes tasks and servers.')
  228. n.addKnob(k)
  229. n.knob('dept').clearFlag(nuke.STARTLINE)
  230. # Task
  231. k = nuke.Enumeration_Knob('task', 'Task', listTasks)
  232. n.addKnob(k)
  233. n.knob('task').clearFlag(nuke.STARTLINE)
  234. k = nuke.String_Knob('element', 'Element')
  235. k.setTooltip('Optional Element.')
  236. n.addKnob(k)
  237. n.knob('element').setValue('')
  238. n.knob('element').clearFlag(nuke.STARTLINE)
  239. # Update from KEnv
  240. k = nuke.PyScript_Knob("reloadConfig", "Reload", "sceneControl.kenvDelete()")
  241. k.setTooltip("Reload project config file.")
  242. n.addKnob(k)
  243. # Season
  244. k = nuke.String_Knob('season', 'Season')
  245. n.addKnob(k)
  246. n.knob('season').setValue(seasonDef)
  247. n.knob('season').setVisible(False)
  248. # Episode
  249. k = nuke.String_Knob('episode', 'Episode')
  250. n.addKnob(k)
  251. n.knob('episode').setValue(episodeDef)
  252. n.knob('episode').setVisible(False)
  253. # _______________________________________________________________
  254. k = nuke.Text_Knob("divider1", "")
  255. n.addKnob(k)
  256. # _______________________________________________________________
  257. # Sequence
  258. k = nuke.String_Knob('sequence', 'Seq')
  259. k.setTooltip(
  260. "can be a sequence number or gen when doing generic tasks.\n\ncomp_001_010.comp_v01.ms.nk\ncomp_gen.footageIngest_v01.ms.nk")
  261. n.addKnob(k)
  262. n.knob('sequence').setValue(seqDef)
  263. # Shot
  264. k = nuke.String_Knob('shot', 'Shot')
  265. k.setTooltip(
  266. "can be a shot number or gen in a multiShot context.\n\ncomp_001_010.comp_v01.ms.nk\ncomp_001_gen.comp_v01.ms.nk")
  267. n.addKnob(k)
  268. n.knob('shot').setValue(shotDef)
  269. n.knob('shot').clearFlag(nuke.STARTLINE)
  270. # Major Version
  271. k = nuke.Int_Knob('major_version', 'Major')
  272. n.addKnob(k)
  273. k.setTooltip('Increment Major Version and save script')
  274. n.knob('major_version').setValue(major_version)
  275. k = nuke.PyScript_Knob('increment_major_version', '+', 'sceneControl.increment_major_version()')
  276. n.addKnob(k)
  277. # Minor Version
  278. k = nuke.Int_Knob('minor_version', 'Minor')
  279. n.addKnob(k)
  280. k.setTooltip('Increment Minor Version and save script')
  281. n.knob('minor_version').setValue(minor_version)
  282. n.knob('minor_version').clearFlag(nuke.STARTLINE)
  283. k = nuke.PyScript_Knob('increment_minor_version', '+', 'sceneControl.increment_minor_version()')
  284. n.addKnob(k)
  285. # Save
  286. k = nuke.PyScript_Knob('save_script', 'Save', 'sceneControl.save_script()')
  287. k.setTooltip('Save Script with current Major and Minor')
  288. n.addKnob(k)
  289. # Overwrite
  290. k = nuke.Boolean_Knob('overwrite', 'Overwrite')
  291. k.setTooltip('Automatically overwrite Scriptfiles without asking.')
  292. n.addKnob(k)
  293. n.knob('overwrite').setValue(0)
  294. n.knob('overwrite').setVisible(True)
  295. # Info / Comment
  296. k = nuke.String_Knob('info', 'Info')
  297. k.setTooltip('Additional (mandatory) File Info.')
  298. n.addKnob(k)
  299. n.knob('info').setValue(info)
  300. # User Short
  301. k = nuke.String_Knob('user', 'User')
  302. n.addKnob(k)
  303. k.setTooltip('User Short. Reading Env Variable: USER')
  304. n.knob('user').setValue(user)
  305. n.knob('user').clearFlag(nuke.STARTLINE)
  306. # Divider _______________________________________________________________
  307. k = nuke.Text_Knob("divider2", "")
  308. n.addKnob(k)
  309. # _______________________________________________________________
  310. # Foldername preview
  311. k = nuke.String_Knob('folder', 'Folder')
  312. n.addKnob(k)
  313. n.knob('folder').setValue('')
  314. n.knob('folder').setEnabled(False)
  315. k.setTooltip('Save folder Preview.')
  316. # Foldername preview
  317. k = nuke.Boolean_Knob('useEnvProjectRoot', 'Use Env Project Root')
  318. n.addKnob(k)
  319. n.knob('useEnvProjectRoot').setValue(USE_ENV_PROJECT_ROOT)
  320. k.setTooltip('Use env variables for 2d and 3d servers set in the site_config.\nUse these env variables before nuke startup.')
  321. n.knob('useEnvProjectRoot').clearFlag(nuke.STARTLINE)
  322. # Filename preview
  323. k = nuke.String_Knob('file', 'File')
  324. n.addKnob(k)
  325. n.knob('file').setValue('')
  326. n.knob('file').setEnabled(False)
  327. k.setTooltip('Save file Preview.')
  328. # Divider _______________________________________________________________
  329. k = nuke.Text_Knob("divider3", "")
  330. n.addKnob(k)
  331. # _______________________________________________________________
  332. # FrameStart
  333. k = nuke.Int_Knob('fStart', 'Start')
  334. n.addKnob(k)
  335. k.setTooltip('Startframe')
  336. n.knob('fStart').setValue(start)
  337. # FrameCutIn
  338. k = nuke.Int_Knob('fCutIn', 'CutIn')
  339. n.addKnob(k)
  340. k.setTooltip('CutIn')
  341. n.knob('fCutIn').setValue(cutIn)
  342. n.knob('fCutIn').clearFlag(nuke.STARTLINE)
  343. # FrameCutOut
  344. k = nuke.Int_Knob('fCutOut', 'CutOut')
  345. n.addKnob(k)
  346. k.setTooltip('CutOut')
  347. n.knob('fCutOut').setValue(cutOut)
  348. n.knob('fCutOut').clearFlag(nuke.STARTLINE)
  349. # FrameEnd
  350. k = nuke.Int_Knob('fEnd', 'End')
  351. n.addKnob(k)
  352. k.setTooltip('Endframe')
  353. n.knob('fEnd').setValue(end)
  354. n.knob('fEnd').clearFlag(nuke.STARTLINE)
  355. # Button Get Framerange (ftrack)
  356. k = nuke.PyScript_Knob("get_framerange", "Get Range", "sceneControl.get_framerange(nuke.thisNode())")
  357. n.addKnob(k)
  358. n.knob("get_framerange").setTooltip("Get Framerange from FTrack.\nPlease check you firewall rules and and allow ftrack ip 104.155.3.128 on port 443")
  359. # Button Set Framerange
  360. k = nuke.PyScript_Knob("set_framerange", "Set Range", "sceneControl.set_framerange(nuke.thisNode())")
  361. n.addKnob(k)
  362. n.knob("set_framerange").setTooltip("Set Framerange from SceneControl Interface")
  363. n.knob("set_framerange").clearFlag(nuke.STARTLINE)
  364. # Comment
  365. k = nuke.Multiline_Eval_String_Knob("comment", "Comment")
  366. n.addKnob(k)
  367. n.knob("comment").setValue(comment)
  368. # Update / publish
  369. if UPDATE_TOOLSET:
  370. # Button update Layer
  371. k = nuke.PyScript_Knob("update_layer", "Update Layer", "sceneControl.update_layer()")
  372. n.addKnob(k)
  373. n.knob("update_layer").setFlag(nuke.STARTLINE)
  374. # Button connect all Layers
  375. k = nuke.PyScript_Knob("autoconnect_layers", "Connect Layers", "sceneControl.autoconnect_layers(nuke.thisNode())")
  376. n.addKnob(k)
  377. n.knob("autoconnect_layers").setFlag(nuke.STARTLINE)
  378. # Button remove all layers
  379. k = nuke.PyScript_Knob("remove_all_layers", "Remove All Layers", "sceneControl.remove_all_layers(nuke.thisNode())")
  380. n.addKnob(k)
  381. n.knob("remove_all_layers").setTooltip("Removes all Layers in SceneControl.")
  382. # Button delete all reads
  383. k = nuke.PyScript_Knob("remove_scnctrl_reads", "Delete All Reads",
  384. "sceneControl.remove_scnctrl_reads(nuke.thisNode())")
  385. n.addKnob(k)
  386. n.knob("remove_scnctrl_reads").setTooltip("Deletes all reads created by SceneControl.")
  387. n.knob("remove_scnctrl_reads").setFlag(nuke.STARTLINE)
  388. n.knob("remove_scnctrl_reads").setVisible(False)
  389. # Button publish Shot
  390. k = nuke.PyScript_Knob("publish_shot", "Publish", "sceneControl.publish_shot()")
  391. n.addKnob(k)
  392. n.knob("publish_shot").setFlag(nuke.STARTLINE)
  393. # invisible helpers
  394. # helper
  395. k = nuke.Int_Knob("layerNum", "Slots")
  396. n.addKnob(k)
  397. n.knob("layerNum").setValue(0)
  398. n.knob("layerNum").setVisible(False)
  399. # used for resolving expressions
  400. k = nuke.EvalString_Knob("eval_helper", "eval_helper")
  401. n.addKnob(k)
  402. n.knob("eval_helper").setValue("")
  403. n.knob("eval_helper").setVisible(False)
  404. # for debug disable above
  405. k = nuke.Boolean_Knob("stereoToggle", "Stereo Toggle")
  406. n.addKnob(k)
  407. n.knob("stereoToggle").setValue(0)
  408. n.knob("stereoToggle").setVisible(False)
  409. # used for resolving expressions
  410. k = nuke.EvalString_Knob("precomp_output", "Precomp Output")
  411. n.addKnob(k)
  412. n.knob("precomp_output").setValue("")
  413. n.knob("precomp_output").setVisible(False)
  414. # for debug disable above
  415. k = nuke.Boolean_Knob("debug", "Debug")
  416. n.addKnob(k)
  417. n.knob("debug").setValue(1)
  418. n.knob("debug").setVisible(False)
  419. # end helper
  420. # return sceneControl Object
  421. sc = nuke.toNode(n.name())
  422. return sc
  423. def initSceneControlValues(sceneControl):
  424. if sceneControl is not None:
  425. k = sceneControl.knobs()
  426. # debug
  427. k['debug'].setValue(DEBUG)
  428. proj = checkEnvEntry('PROJECT')
  429. if proj is None:
  430. proj = GENFOLDER
  431. kenvReloadTasks()
  432. proj = checkEnvEntry('PROJECT')
  433. k['project'].setValue(proj)
  434. try:
  435. k['user'].setValue(checkEnvEntry('USER'))
  436. except:
  437. print('SceneControl: Warning. Please enter your shortname.')
  438. # KEnv functions
  439. def kenvCheck():
  440. try:
  441. nuke.kenv
  442. except:
  443. kenvCreate()
  444. print('SceneControl: Info. Creating kenv.')
  445. def kenvModuleLoaded():
  446. from imp import reload
  447. try:
  448. import KEnv
  449. reload(KEnv)
  450. except:
  451. print('SceneControl: Error. No KEnv module found')
  452. return False
  453. return KEnv
  454. def kenvCreate():
  455. try:
  456. project = os.environ['PROJECT']
  457. except:
  458. project = GENFOLDER
  459. # KEnv
  460. env = KEnv.create(PROJECT=project, APP_ID='nuke')
  461. # save KEnv to Nuke to access if by other nodes / tools
  462. nuke.kenv = env
  463. def kenvDelete():
  464. try:
  465. del(nuke.kenv)
  466. print('SceneControl: Info. Deleting nuke.kenv.')
  467. except:
  468. print('SceneControl: Info. nuke.kenv not found.')
  469. def kenvReloadTasks():
  470. sceneControl = getSceneControl()
  471. k = sceneControl.knobs()
  472. kenvCheck()
  473. # KEnv query
  474. dept = nuke.kenv.get('DEPARTMENTS')
  475. k['dept'].setValues(dept)
  476. tasks = nuke.kenv.get('TASKS', DEPT=k['dept'].value(), APP_ID='nuke')
  477. k['task'].setValues(tasks)
  478. return tasks
  479. def kenvGetWriteOutput(writeTask, writeElement, writeInfo, ext):
  480. sceneControl = getSceneControl()
  481. k = sceneControl.knobs()
  482. kenvCheck()
  483. # debug
  484. if k["debug"].getValue():
  485. print(('SceneControl: Debug. WriteTask: %s, WriteElement: %s, WriteInfo: %s') % (writeTask, writeElement, writeInfo))
  486. # useEnvProjectRoot
  487. useEnv = k['useEnvProjectRoot'].value()
  488. if writeElement == '':
  489. writeElement = None
  490. if writeInfo == '':
  491. writeInfo = None
  492. if writeTask.lower() == 'scripttask':
  493. # get task from sceneControl and not from the write node
  494. # sceneControl task
  495. task = k["task"].value()
  496. writeTask = task
  497. # KEnv query
  498. renderpath = kenvQuery('RENDER_2D_FILE', element=writeElement, task=writeTask, minor_version=None, info=writeInfo, ext=ext, USE_ENV_PROJECTROOT=useEnv)
  499. else:
  500. # KEnv query
  501. renderpath = kenvQuery('PRECOMP_FILE', element=writeElement, task=writeTask, minor_version=None, info=writeInfo, ext=ext, USE_ENV_PROJECTROOT=useEnv)
  502. return renderpath
  503. def kenvGetWorkFile():
  504. sceneControl = getSceneControl()
  505. k = sceneControl.knobs()
  506. kenvCheck()
  507. info = k['info'].value()
  508. if info == '':
  509. info = None
  510. element = k['element'].value()
  511. if element == '':
  512. element = None
  513. # KEnv query
  514. script = kenvQuery('WORK_FILE', element=element, info=info)
  515. dir = kenvQuery('WORK_DIR', element=element, info=info)
  516. try:
  517. k['folder'].setValue(dir+'/')
  518. except:
  519. print(('SceneControl: Error. Error setting directory: %s') % dir)
  520. try:
  521. k['file'].setValue(script.split('/')[-1])
  522. except:
  523. print(('SceneControl: Error. Error setting file: %s') % script)
  524. # main Kenv Query
  525. def kenvQuery(query , **kwargs):
  526. # sceneControl
  527. sceneControl = getSceneControl()
  528. k = sceneControl.knobs()
  529. kenvCheck()
  530. # sceneControl values:
  531. debug = k['debug'].getValue()
  532. project = k['project'].value()
  533. dept = k['dept'].value()
  534. sequence = k['sequence'].value()
  535. shot = k['shot'].value()
  536. element = k['element'].value()
  537. task = k['task'].value()
  538. major_version = int(k['major_version'].value())
  539. minor_version = int(k['minor_version'].value())
  540. user = k['user'].value()
  541. info = k['info'].value()
  542. ext = 'exr'
  543. app_id = 'nuke'
  544. # useEnvProjectRoot
  545. useEnv = k['useEnvProjectRoot'].value()
  546. # read out kwargs
  547. for k,v in kwargs.items():
  548. if k == 'project':
  549. project = v
  550. if k == 'dept':
  551. dept = v
  552. if k == 'sequence':
  553. sequence = v
  554. if k == 'shot':
  555. shot = v
  556. if k == 'element':
  557. element = v
  558. if k == 'task':
  559. task = v
  560. if k == 'major_version':
  561. major_version = v
  562. if k == 'minor_version':
  563. minor_version = v
  564. if k == 'user':
  565. user = v
  566. if k == 'info':
  567. info = v
  568. if k == 'ext':
  569. ext = v
  570. if k == 'app_id':
  571. app_id = v
  572. if k == 'useEnv':
  573. useEnv = v
  574. # info
  575. infostr=''
  576. if info == '':
  577. info = None
  578. infostr = 'None'
  579. # element
  580. elementstr=''
  581. if element == '':
  582. element = None
  583. elementstr = 'None'
  584. # debug
  585. if debug:
  586. print('SceneControl: Debug kenv query:')
  587. print('PROJECT: ' + project)
  588. print('SHOT: ' + shot)
  589. print('SEQUENCE: ' + sequence)
  590. print('DEPT: ' + dept)
  591. print('TASK: ' + task)
  592. print('MAJOR_VERSION: ' + str(int(major_version)))
  593. if minor_version is None:
  594. print('MINOR_VERSION: ' + 'None')
  595. else:
  596. print('MINOR_VERSION: ' + str(int(minor_version)))
  597. print('ELEMENT: ' + elementstr)
  598. print('INFO: ' + infostr)
  599. print('USER: ' + user)
  600. print('EXT: ' + ext)
  601. print('APP_ID: ' + app_id)
  602. # KEnv
  603. if minor_version is None:
  604. result = nuke.kenv.get(query, PROJECT=project, DEPT=dept, SEQUENCE=sequence, SHOT=shot, ELEMENT=element, TASK=task, MAJOR_VERSION=int(major_version), INFO=info, EXT=ext, USER=user, APP_ID=app_id, USE_ENV_PROJECTROOT=useEnv)
  605. else:
  606. result = nuke.kenv.get(query, PROJECT=project, DEPT=dept, SEQUENCE=sequence, SHOT=shot, ELEMENT=element, TASK=task, MAJOR_VERSION=int(major_version), MINOR_VERSION=int(minor_version), INFO=info, EXT=ext, USER=user, APP_ID=app_id, USE_ENV_PROJECTROOT=useEnv)
  607. if debug:
  608. print('SceneControl: Debug kenv query: ' + result)
  609. return result
  610. # called from write nodes
  611. def kenvWriteSetPath(n):
  612. print('Our_Write: Info. Setting output file path')
  613. sceneControl = getSceneControl()
  614. k = sceneControl.knobs()
  615. kenvCheck()
  616. #debug
  617. if k["debug"].getValue():
  618. print(('SceneControl: Debug. Setting path on: %s') % n.name())
  619. subtask = n.knob('subtask').value()
  620. if subtask is None:
  621. subtask = ''
  622. element = n.knob('element').value()
  623. if element == '':
  624. element = None
  625. info = n.knob('info').value()
  626. if info == '':
  627. info = None
  628. ext = n.knob('extension').value()
  629. # dummy
  630. file = ''
  631. file = kenvGetWriteOutput(subtask, element, info, ext)
  632. if file != '':
  633. try:
  634. n.knob('file').setValue(file)
  635. except:
  636. pass
  637. return
  638. def kenvWriteReloadSubTasks(n):
  639. sceneControl = getSceneControl()
  640. kenvCheck()
  641. # KEnv query
  642. tasks = nuke.kenv.get('SUBTASKS_2D')
  643. try:
  644. n.knob('subtask').setValues(tasks)
  645. except:
  646. pass
  647. return
  648. # helpers
  649. # todo: set selected Reads to framerange
  650. def setIgnoreFlag(state):
  651. s = nuke.selectedNodes()
  652. if len(s) == 0:
  653. nuke.message("Please select some Nodes first.")
  654. return
  655. for n in s:
  656. if n.Class() == 'Write' or n.Class() == 'DeepWrite':
  657. try:
  658. n.knobs()['ignore'].setValue(state)
  659. except:
  660. print(('SceneControl: Warning. Cannot find ignore flag on: %s') % n.name())
  661. def setErrorMode():
  662. n = nuke.selectedNodes()
  663. if len(n) == 0:
  664. nuke.message("Please select some Nodes first.")
  665. return
  666. w = nuke.nodes.Read()
  667. onerror = w['on_error'].values()
  668. # spaces in the names
  669. quoted = ['{%s}' % c for c in onerror]
  670. p = nuke.Panel('Missing Frames')
  671. p.addEnumerationPulldown('Missing Frames', ' '.join(quoted))
  672. p.show()
  673. ret = p.value('Missing Frames')
  674. sel = nuke.selectedNodes()
  675. for s in sel:
  676. if s.Class() == "Read" or s.Class() == "DeepRead":
  677. s.knobs()['on_error'].setValue(ret)
  678. def setOcioRole():
  679. n = nuke.selectedNodes()
  680. if len(n) == 0:
  681. nuke.message("No node(s) selected.")
  682. # create temporary write node
  683. w = nuke.nodes.Write(file_type='exr')
  684. colorspace = w['colorspace'].values()
  685. # delete write node
  686. nuke.delete(w)
  687. choice = []
  688. for s in colorspace:
  689. if not s.startswith('Colorspaces/'):
  690. choice.append(s.split('\t')[0])
  691. else:
  692. choice.append(s)
  693. # spaces in the names
  694. quoted = ['{%s}' % c for c in choice]
  695. # TODO: create cascading Enumeration pulldown. Not possible with panel?
  696. p = nuke.Panel('Colorspace')
  697. p.addEnumerationPulldown('Colorspace', ' '.join(quoted))
  698. p.show()
  699. ret = p.value('Colorspace')
  700. if ret is not None:
  701. for s in n:
  702. if s.Class() == "Read" or s.Class() == "Write":
  703. s.knobs()['colorspace'].setValue(ret)
  704. def setDebug(state):
  705. sceneControl = getSceneControl()
  706. if sceneControl is None:
  707. print('SceneControl: Error. No SceneControl node found. Exiting.')
  708. return
  709. k = sceneControl.knobs()
  710. k['debug'].setValue(state)
  711. if state is False:
  712. print('SceneControl: Info. Set SceneControl Debug Mode to: False')
  713. else:
  714. print('SceneControl: Info. Set SceneControl Debug Mode to: True')
  715. def deselectAll():
  716. for each in nuke.allNodes():
  717. each.knob("selected").setValue(False)
  718. return
  719. def getFilename():
  720. return nuke.Root()["name"].getValue()
  721. def checkEnvEntry(value):
  722. try:
  723. val = os.environ[value]
  724. except:
  725. print(('SceneControl: Info. Env variable %s not set.') %value)
  726. return None
  727. return val
  728. def find_node_by_type(nodename, nodeclass):
  729. nodes = nuke.allNodes()
  730. for n in nodes:
  731. if n.Class() == nodeclass:
  732. if n.knob("label").getValue().lower() == nodename.lower():
  733. return n
  734. return None
  735. def updateWriteNodePaths():
  736. nodes = nuke.allNodes()
  737. for n in nodes:
  738. if n.Class() == 'Write' or n.Class() == 'DeepWrite':
  739. try:
  740. if n.knobs()['ignore'].value() == True:
  741. print('SceneControl: Info. Found ignore flag on %s. Skipping.' % n.name())
  742. else:
  743. try:
  744. print('SceneControl: Info. Setting output file on %s.' % n.name())
  745. nuke.toNode(n.name()).knobs()['set'].execute()
  746. except:
  747. print('SceneControl: Error. Error setting output file on %s.' % n.name())
  748. except:
  749. print ('SceneControl: Info. Skipping Node %s. Old Write Node. Consider creating a new one.' % n.name())
  750. def updateWriteNodeConfig():
  751. import sceneControl
  752. # 'task' for legacy write nodes
  753. customKnobs = (
  754. 'extension', 'ext', 'ver', 'explore', 'divider3', 'playinrv', 'pushtorv', 'pushtorvappend', 'divider2', 'ignore', 'divider1', 'set',
  755. 'info', 'element', 'subtask', 'task', 'w_reload', 'keller')
  756. # save these for reapplying later on
  757. saveKnobs = ('info', 'element', 'subtask', 'ignore')
  758. # get all reads
  759. nodes = [node for node in nuke.selectedNodes() if node.Class() == 'Write']
  760. for n in nodes:
  761. knobs = n.knobs()
  762. info = ''
  763. element = ''
  764. subtask = ''
  765. for c in customKnobs:
  766. # save config
  767. try:
  768. info = knobs['info'].value()
  769. element = knobs['element'].value()
  770. subtask = knobs['subtask'].value()
  771. ignore = knobs['ignore'].value()
  772. except:
  773. pass
  774. try:
  775. n.removeKnob(knobs[c])
  776. except:
  777. pass
  778. # create new Keller tab
  779. sceneControl.createCustomWrite(n)
  780. # refresh subtasks
  781. sceneControl.kenvWriteReloadSubTasks(n)
  782. # restore old values
  783. try:
  784. n.knobs()['info'].setValue(info)
  785. except:
  786. print('SceneControl: Error. Node %s. Cannot set value on knob: %s') % (n.name(), info)
  787. try:
  788. n.knobs()['element'].setValue(element)
  789. except:
  790. print('SceneControl: Error. Node %s. Cannot set value on knob: %s') % (n.name(), element)
  791. try:
  792. n.knobs()['subtask'].setValue(subtask)
  793. except:
  794. print('SceneControl: Error. Node %s. Cannot set value on knob: %s') % (n.name(), subtask)
  795. return
  796. def refresh_read_nodes():
  797. nodes = nuke.selectedNodes()
  798. if len(nodes)==0:
  799. nodes = nuke.allNodes()
  800. print('SceneControl: Info. No node selected. Reloading all reads.')
  801. for n in nodes:
  802. if n.Class() == 'Read' or n.Class() == 'DeepRead':
  803. try:
  804. nuke.toNode(n.name()).knobs()['reload'].execute()
  805. print('SceneControl: Info. Reloading %s.' % n.name())
  806. except:
  807. pass
  808. def autoconnect_layers(node):
  809. n = nuke.thisNode()
  810. nu = n["layerNum"].getValue()
  811. num = int(nu)
  812. for i in range(1, num + 1):
  813. create_deepreadnode(i, autoconnect=True)
  814. create_readnode(i, autoconnect=True)
  815. return
  816. # write nodes
  817. def createCustomWrite(n):
  818. # Task
  819. '''
  820. taskList = ("comp",)
  821. try:
  822. taskList = sceneControl.kenvReloadTasks()
  823. except:
  824. print("Our_Write: Error. Cannot call sceneControl.kenvReloadTasks()")
  825. pass
  826. '''
  827. try:
  828. tab = n.knobs()['keller'].value()
  829. except:
  830. tab = None
  831. if tab is None:
  832. pass
  833. else:
  834. # already existing
  835. return
  836. # create tab
  837. print("Our_Write: Info. Creating KellerTab")
  838. k = nuke.Tab_Knob('keller', 'Keller')
  839. n.addKnob(k)
  840. exts = n.knobs()['file_type'].values()
  841. k = nuke.Enumeration_Knob('extension', 'Extension', exts)
  842. n.addKnob(k)
  843. n.knob('extension').setValue('exr')
  844. n.knob('extension').setFlag(nuke.STARTLINE)
  845. # task
  846. subTaskList = ('--------------->',)
  847. k = nuke.Enumeration_Knob('subtask', 'Subtask', subTaskList)
  848. k.setTooltip('Defaults to the Task selected in sceneControl, ignoring Element and Info.\nAll other subtasks are pre-renders and get rendered into the precomp (=prerender) directory.')
  849. n.addKnob(k)
  850. n.knob('subtask').setFlag(nuke.STARTLINE)
  851. # Reload
  852. k = nuke.PyScript_Knob('w_reload', 'Reload', 'sceneControl.kenvWriteReloadSubTasks(nuke.thisNode())')
  853. k.setTooltip('Reloads the subtasks. If the project_config.py was changed you need to re-init the config with the SceneControl button \'reload\'.')
  854. k.setTooltip('Reload Tasks')
  855. n.addKnob(k)
  856. # element
  857. k = nuke.String_Knob('element', 'Element')
  858. k.setTooltip('Optional Specifier. For example [BG]_denoise. [FG]_denoise.')
  859. n.addKnob(k)
  860. n.knob('element').setValue('')
  861. # info
  862. k = nuke.String_Knob('info', 'Info')
  863. k.setTooltip('Optional Info before Framenumber.\nPRO_comp3d_001_010.comp3d_v008.[acescg].%04d.exr')
  864. n.addKnob(k)
  865. n.knob('info').setValue('')
  866. # set
  867. k = nuke.PyScript_Knob('set', 'Set', 'sceneControl.kenvWriteSetPath(nuke.thisNode())')
  868. k.setTooltip('Set Output Path of this node')
  869. n.addKnob(k)
  870. n.knob('set').setFlag(nuke.STARTLINE)
  871. # _______________________________________________________________
  872. k = nuke.Text_Knob("divider1", "")
  873. n.addKnob(k)
  874. # _______________________________________________________________
  875. # ignore
  876. k = nuke.Boolean_Knob("ignore", "ignore in sceneControl")
  877. n.addKnob(k)
  878. n.knob("ignore").setValue(0)
  879. # _______________________________________________________________
  880. k = nuke.Text_Knob("divider2", "")
  881. n.addKnob(k)
  882. # _______________________________________________________________
  883. # play in new rv
  884. k = nuke.PyScript_Knob("playinrv", "Play in RV", "playInRV.playInRV(nuke.thisNode().knob('file').getValue(),0)")
  885. n.addKnob(k)
  886. n.knob("playinrv").setTooltip("Opens new instance of RV")
  887. n.knob("playinrv").setFlag(nuke.STARTLINE)
  888. # push to rv
  889. k = nuke.PyScript_Knob("pushtorv", "Push to RV", "playInRV.playInRV(nuke.thisNode().knob('file').getValue(),1)")
  890. n.addKnob(k)
  891. n.knob("pushtorv").setTooltip("Push to tagged RV. Will open RV and uses this instance to directly push sequences.")
  892. # push to rv / append
  893. k = nuke.PyScript_Knob("pushtorvappend", "Push to RV (append)", "playInRV.playInRV(nuke.thisNode().knob('file').getValue(),2)")
  894. n.addKnob(k)
  895. n.knob("pushtorvappend").setTooltip("Push to RV and append to existing sources")
  896. n.knob("pushtorvappend").clearFlag(nuke.STARTLINE)
  897. # _______________________________________________________________
  898. k = nuke.Text_Knob("divider3", "")
  899. n.addKnob(k)
  900. # _______________________________________________________________
  901. # explore
  902. k = nuke.PyScript_Knob("explore", "Explore", "exploreThis.exploreThis()")
  903. n.addKnob(k)
  904. n.knob("explore").setTooltip("Open Folder")
  905. # version
  906. k = nuke.Array_Knob("ver", "Version")
  907. n.addKnob(k)
  908. n.knob("ver").setValue(WRITENODE_VERSION)
  909. n.knob("ver").setVisible(False)
  910. # label
  911. if n.knob("label").value() != "":
  912. n.knob("label").setValue('\n' + WRITENODE_LABEL)
  913. else:
  914. n.knob("label").setValue(WRITENODE_LABEL)
  915. # saving
  916. def save_script():
  917. sceneControl = getSceneControl()
  918. k = sceneControl.knobs()
  919. # overwrite existing scene without notice?
  920. owrite = k['overwrite'].value()
  921. # info
  922. info = k['info'].value()
  923. if info == '':
  924. info = None
  925. # element
  926. element = k['element'].value()
  927. if element == '':
  928. element = None
  929. # useEnvProjectRoot
  930. useEnv = k['useEnvProjectRoot'].value()
  931. # KEnv Query
  932. script = kenvQuery('WORK_2D_SCENE_FILE',useEnv = False)
  933. # get work_2d_scene_file
  934. print(('SceneControl: Info. Checking script file: %s') %script)
  935. # old Scriptname
  936. oldname = nuke.Root()["name"].value()
  937. # Nuke set filename
  938. nuke.Root()["name"].setValue(script)
  939. # check if folder exists
  940. folder = os.path.dirname(script)
  941. if not os.path.exists(folder):
  942. os.makedirs(folder)
  943. else:
  944. # folder existing. Moving on
  945. pass
  946. # check if file exists
  947. if os.path.isfile(script):
  948. if owrite:
  949. # good to go: change write nodes first
  950. updateWriteNodePaths()
  951. nuke.scriptSave()
  952. else:
  953. s = "SceneControl. Overwrite Nuke Script? %s" % script
  954. overwrite = nuke.ask(s)
  955. if overwrite:
  956. # good to go: change write nodes first
  957. updateWriteNodePaths()
  958. nuke.scriptSave()
  959. else:
  960. nuke.Root()["name"].setValue(oldname)
  961. else:
  962. # good to go: change write nodes first
  963. updateWriteNodePaths()
  964. nuke.scriptSave()
  965. def increment_major_version():
  966. sceneControl = getSceneControl()
  967. k = sceneControl.knobs()
  968. major = k["major_version"].getValue()
  969. major = int(major) + 1
  970. k["major_version"].setValue(major)
  971. k["minor_version"].setValue(1)
  972. # call save script
  973. save_script()
  974. return
  975. def increment_minor_version():
  976. sceneControl = getSceneControl()
  977. k = sceneControl.knobs()
  978. minor = k["minor_version"].getValue()
  979. minor = int(minor) + 1
  980. k["minor_version"].setValue(minor)
  981. # call save script
  982. save_script()
  983. return
  984. # framerange
  985. def get_framerange_OLD(node):
  986. '''
  987. # TODO: ftrack query or KEnv query
  988. # Connect to FTrack
  989. frameStart = 1001
  990. frameCutIn = 1010
  991. frameCutOut = 1100
  992. frameEnd = 1109
  993. n = nuke.thisNode()
  994. k = n.knobs()
  995. sequence = k["sequence"].getText()
  996. shot = k["shot"].getText()
  997. user = k["shortname"].getText()
  998. if user == "":
  999. nuke.message("Please fill out your shortname in the User field. E.g. \"ms\"")
  1000. return
  1001. try:
  1002. conn = FTrackConnector(shortname=user)
  1003. project = conn.getProject("drr")
  1004. shot = project.getShot(sequence, shot)
  1005. frameStart = shot.get("custom_attributes").get("fstart")
  1006. frameCutIn = shot.get("custom_attributes").get("fcutin")
  1007. frameCutOut = shot.get("custom_attributes").get("fcutout")
  1008. frameEnd = shot.get("custom_attributes").get("fend")
  1009. except Exception as e:
  1010. nuke.message(
  1011. "No Connection could be established. Check Firewall and enable 104.155.61.233 Port 443\n\n" + str(e))
  1012. node.knob("fStart").setValue(int(frameStart))
  1013. node.knob("fCutIn").setValue(int(frameCutIn))
  1014. node.knob("fCutOut").setValue(int(frameCutOut))
  1015. node.knob("fEnd").setValue(int(frameEnd))
  1016. return None
  1017. '''
  1018. def get_framerange(node):
  1019. import ftrack_tools
  1020. sceneControl = getSceneControl()
  1021. k = sceneControl.knobs()
  1022. proj = k['project'].value()
  1023. seq = k['sequence'].value()
  1024. shot = k['shot'].value()
  1025. # ftrack query
  1026. p = ftrack_tools.get_project(proj)
  1027. if proj == 'HOTZ':
  1028. proj = 'HOT'
  1029. shotcode = proj + '_' + seq + '_' + shot
  1030. if k["debug"].getValue():
  1031. print(('SceneControl: Debug. Project: %s') %proj)
  1032. print(('SceneControl: Debug. Sequence: %s') % seq)
  1033. print(('SceneControl: Debug. Shot: %s') % shot)
  1034. print(('SceneControl: Debug. FTrack Shotcode: %s') %shotcode)
  1035. s = p.get_shot(shotcode)
  1036. st,en = s.get_framerange()
  1037. ha = s.get_handles()
  1038. k['fStart'].setValue(int(st))
  1039. k['fCutIn'].setValue(int(st) + int(ha))
  1040. k['fEnd'].setValue(int(en))
  1041. k['fCutOut'].setValue(int(en) - int(ha))
  1042. return None
  1043. def set_framerange(node):
  1044. frameCutIn = node.knob("fCutIn").getValue()
  1045. frameCutOut = node.knob("fCutOut").getValue()
  1046. nuke.root()["first_frame"].setValue(frameCutIn)
  1047. nuke.root()["last_frame"].setValue(frameCutOut)
  1048. return None
  1049. def remove_expressions():
  1050. #todo: create **kwargs for replacement
  1051. n = nuke.thisNode()
  1052. k = n.knobs()
  1053. nodes = nuke.allNodes()
  1054. for no in nodes:
  1055. if no.Class() == "Read" or no.Class() == "DeepRead" or no.Class() == "Write":
  1056. s = no.knob("file").getValue()
  1057. k["eval_helper"].setValue(s)
  1058. res = k["eval_helper"].evaluate()
  1059. res = res.replace("\\", "/")
  1060. res = res.replace("//hades/p/_projekte/DRR", "$env(JOB)")
  1061. s = no.knob("file").setValue(res)
  1062. return None
  1063. def remove_expression_links():
  1064. nodes = nuke.allNodes()
  1065. for n in nodes:
  1066. if n.Class() == "Read" or n.Class() == "DeepRead" or n.Class() == "Write":
  1067. for k in n.knobs():
  1068. n.knobs()[k].clearAnimated()
  1069. return None
  1070. def replace_frame_with_padded_frames():
  1071. nodes = nuke.allNodes()
  1072. for n in nodes:
  1073. if n.Class() == "Read" or n.Class() == "DeepRead":
  1074. file = n.knob("file").getValue()
  1075. sub = file.split(".")[-2]
  1076. file = file.replace(sub, "####")
  1077. n.knob("file").setValue(file)
  1078. return None
  1079. # layer
  1080. def get_layer_versions():
  1081. # TODO: filter out temporary files: tmp, temp, ifd, ass
  1082. sceneControl = getSceneControl()
  1083. k = sceneControl.knobs()
  1084. # get renderpath to look for layers
  1085. path = kenvQuery('RENDER_3D_DIR')
  1086. t = k["task"].value()
  1087. task = '_' + t
  1088. folder = os.path.dirname(str(path))
  1089. if not os.path.exists(folder):
  1090. msg = "SceneControl. Error.\nNo renders found in:\n%s\nIs the task %s correct?" % (path, t)
  1091. nuke.message(msg)
  1092. return
  1093. # find top folders in renderdir of current shot in current department
  1094. folders = [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
  1095. # debug
  1096. if k["debug"].getValue():
  1097. print(('SceneControl: Debug. Folders found: %s') %folders)
  1098. # dict holding info about layer and their version.
  1099. layer_dict = {}
  1100. for f in folders:
  1101. print(('SceneControl: Info: Adding folder: %s') %f)
  1102. # extract layer name
  1103. lay = f.split('.')[1]
  1104. pattern = re.compile('_[vV]\d+')
  1105. layer = re.sub(pattern, "", lay)
  1106. layer = layer.replace(task, '')
  1107. if k["debug"].getValue():
  1108. print(('SceneControl: Debug. Layer: %s') % layer)
  1109. # extract version string
  1110. pattern2 = re.compile('[vV]\d+')
  1111. ver = pattern2.findall(f)
  1112. version = ver[-1].replace('v', '').replace('V', '')
  1113. version = int(version)
  1114. if k["debug"].getValue():
  1115. print(('SceneControl: Debug. Version: %s') % version)
  1116. # if layer is already loaded
  1117. if layer in layer_dict:
  1118. # check if version in dict is smaller than found version
  1119. if layer_dict[layer] < version:
  1120. layer_dict[layer] = version
  1121. else:
  1122. pass
  1123. else:
  1124. layer_dict[layer] = version
  1125. if k["debug"].getValue():
  1126. print(('SceneControl: Debug. get_layer_version()) Layerdict: %s') % layer_dict)
  1127. return layer_dict
  1128. def get_layer_versions_OLD():
  1129. sceneControl = getSceneControl()
  1130. k = sceneControl.knobs()
  1131. # renderpath = '//hades/p/_projekte/HOTZ/500_renders/Shots/001/010'
  1132. # path = kenvGetRenderPath()
  1133. path = kenvQuery('RENDER_3D_DIR')
  1134. task = k["task"].value()
  1135. folder = os.path.dirname(str(path))
  1136. if not os.path.exists(folder):
  1137. msg = "SceneControl. Error.\nNo renders found in:\n%s\nIs the Task %s correct?" % (path, task)
  1138. nuke.message(msg)
  1139. return
  1140. # find top folders in renderdir of current shot in current department
  1141. folders = [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
  1142. # debug
  1143. if k["debug"].getValue():
  1144. print(('SceneControl: Debug. Folders found: %s') %folders)
  1145. # dict holding info about layer and their version. BEN:3, SOR:4, ENV:1
  1146. layer_dict = {}
  1147. for f in folders:
  1148. print(('SceneControl: Info: Adding folder: %s') %f)
  1149. # TODO: also add layers with variants. Eg. DRR Layer example: HOT_shots_001_010.beauty_light_v001/HOT_shots_001_010.beauty_light_v001.1023.exr
  1150. try:
  1151. layer = f.split('.')[1].split('_')[0]
  1152. except:
  1153. print(('SceneControl: Error. Layer %s is not conform in naming. Skipping.') %f)
  1154. break
  1155. version = int(f.split('_')[-1].replace('v', ''))
  1156. if layer in layer_dict:
  1157. # check if version in dict is smaller than found version
  1158. if layer_dict[layer] < version:
  1159. layer_dict[layer] = version
  1160. else:
  1161. pass
  1162. else:
  1163. layer_dict[layer] = version
  1164. if k["debug"].getValue():
  1165. print(('SceneControl: Debug. get_layer_version()) Layerdict: %s') % layer_dict)
  1166. return layer_dict
  1167. def update_layer():
  1168. n = nuke.thisNode()
  1169. # get newest files on disk
  1170. layer_dict = get_layer_versions()
  1171. if bool(layer_dict) is True:
  1172. layer_dict_new_entries = OrderedDict(sorted(layer_dict.items(), key=lambda t: t[0]))
  1173. nu = n['layerNum'].getValue()
  1174. num = int(nu)
  1175. # get new entries
  1176. for layer, version in layer_dict.items():
  1177. if num < 1:
  1178. c = 0
  1179. else:
  1180. c = num
  1181. for i in range(1, num + 1):
  1182. if n.knob("layer_name_" + str(i)) is not None and n.knob("layer_name_" + str(i)).getValue() == layer:
  1183. # layer already in list. Just update version
  1184. n.knob("layer_version_" + str(i)).setValue(version)
  1185. del layer_dict_new_entries[layer]
  1186. break
  1187. # new entries
  1188. if len(layer_dict_new_entries) > 0:
  1189. c += 1
  1190. for layer, version in layer_dict_new_entries.items():
  1191. k = nuke.String_Knob("layer_name_" + str(c), str(c))
  1192. n.addKnob(k)
  1193. n.knob("layer_name_" + str(c)).setValue(layer)
  1194. # Version
  1195. k = nuke.Int_Knob("layer_version_" + str(c), "version")
  1196. n.addKnob(k)
  1197. n.knob("layer_version_" + str(c)).clearFlag(nuke.STARTLINE)
  1198. n.knob("layer_version_" + str(c)).setValue(version)
  1199. # Button Read
  1200. func = "sceneControl.create_readnode(" + str(c) + ")"
  1201. name = "create_readnode_" + str(c)
  1202. k = nuke.PyScript_Knob(name, "Read", func)
  1203. n.addKnob(k)
  1204. # Button Deep Read
  1205. func = "sceneControl.create_deepreadnode(" + str(c) + ")"
  1206. name = "create_deepreadnode_" + str(c)
  1207. k = nuke.PyScript_Knob(name, "Deep", func)
  1208. n.addKnob(k)
  1209. # Button Crypto
  1210. #func = "sceneControl.create_readnode(" + str(c) + ")"
  1211. #name = "create_readnode" + str(c)
  1212. #k = nuke.PyScript_Knob(name, "Crypto", func)
  1213. #n.addKnob(k)
  1214. # Include in publish
  1215. k = nuke.Boolean_Knob("include_in_publish_" + str(c), "Publish")
  1216. n.addKnob(k)
  1217. n.knob("include_in_publish_" + str(c)).clearFlag(nuke.STARTLINE)
  1218. n.knob("include_in_publish_" + str(c)).setValue(1)
  1219. n.knob("include_in_publish_" + str(c)).setTooltip("Include this layer in publish.")
  1220. num = num + 1
  1221. c = c + 1
  1222. n.knob("layerNum").setValue(c - 1)
  1223. layer_dict = None
  1224. return
  1225. else:
  1226. # dict is empty
  1227. return
  1228. def remove_layer(c):
  1229. n = nuke.thisNode()
  1230. # remove entire line
  1231. k = "layer_name_" + str(c)
  1232. n.removeKnob(n.knobs()[k])
  1233. k = "layer_version_" + str(c)
  1234. n.removeKnob(n.knobs()[k])
  1235. k = "create_readnode_" + str(c)
  1236. n.removeKnob(n.knobs()[k])
  1237. k = "create_deepreadnode_" + str(c)
  1238. n.removeKnob(n.knobs()[k])
  1239. k = "include_in_publish_" + str(c)
  1240. n.removeKnob(n.knobs()[k])
  1241. # adjust number of layers
  1242. nu = n["layerNum"].getValue()
  1243. nu = nu - 1
  1244. n.knob("layerNum").setValue(int(nu))
  1245. if n.knob("layerNum").getValue() < 0:
  1246. n.knob("layerNum").setValue(0)
  1247. return
  1248. def remove_all_layers(node):
  1249. n = nuke.thisNode()
  1250. nu = n["layerNum"].getValue()
  1251. num = int(nu)
  1252. for i in range(num, 0, -1):
  1253. remove_layer(i)
  1254. return
  1255. # publish
  1256. def publish_shot():
  1257. n = nuke.thisNode()
  1258. k = n.knobs()
  1259. print ("SceneControl: Checking Versions...")
  1260. maximum = return_highest_layer_version()
  1261. major = k["major_version"].getValue()
  1262. if major < maximum:
  1263. if nuke.ask(
  1264. 'SceneControl: Layer found with higher version than the Major file version. Continue with publish?'):
  1265. pass
  1266. else:
  1267. "SceneControl: Terminating Publish"
  1268. return
  1269. print ("SceneControl: Publishing Shot")
  1270. # sequence
  1271. sequence = k["sequence"].getText()
  1272. # shot
  1273. shot = k["shot"].getText()
  1274. # cutIn and cutOut
  1275. frameCutIn = n.knob("fCutIn").getValue()
  1276. frameCutOut = n.knob("fCutOut").getValue()
  1277. # precompCutIn and precompCutOut
  1278. precompframeCutIn = n.knob("pCutIn").getValue()
  1279. precompframeCutOut = n.knob("pCutOut").getValue()
  1280. # eye
  1281. eye = n.knob("eye").getValue()
  1282. # rendered on studio funk farm
  1283. studioFunkRender = n.knob("studio_funk_render").getValue()
  1284. # comment
  1285. comment = k["comment"].getText()
  1286. # shortname
  1287. shortname = k["user"].getText()
  1288. if shortname == "":
  1289. nuke.message("Please fill out your shortname in the User field. E.g. \"ms\"")
  1290. return
  1291. # precomp render path
  1292. major = k["major_version"].getValue()
  1293. major = "v" + str(int(major)).zfill(3)
  1294. path = k["comp_output_path"].getText()
  1295. path = path.replace("MAJORVERSION", str(major))
  1296. output = k["comp_output_file"].getText()
  1297. output = output.replace("MAJORVERSION", str(major))
  1298. path = path.replace("\\", "/")
  1299. precomp = "%s/%s" % (path, output)
  1300. # evaluate expressions
  1301. k["eval_helper"].setValue(precomp)
  1302. precomp = k["eval_helper"].evaluate()
  1303. precomp = precomp.replace("\\", "/")
  1304. frames = precomp.split(".")[-2]
  1305. precomp = precomp.replace(frames, "####")
  1306. precomp_dir = os.path.dirname(precomp)
  1307. # debug
  1308. debug = k["Debug"].getValue()
  1309. # gather Layers and versions to publish (exclude flagged Layers)
  1310. layernum = k["layerNum"].getValue()
  1311. num = int(layernum)
  1312. layer = {}
  1313. publish = {}
  1314. metadata = {}
  1315. skip_copy_layers = []
  1316. for c in range(1, num + 1, 1):
  1317. layername = n.knob("layer_name_" + str(c)).getValue()
  1318. layerversion = n.knob("layer_version_" + str(c)).getValue()
  1319. if n.knob("include_in_publish_" + str(c)).getValue() == 1:
  1320. layer[layername] = str(int(layerversion)).zfill(3)
  1321. if n.knob("copy_layer_" + str(c)).getValue() == 1:
  1322. skip_copy_layers.append(layername)
  1323. # search for readnodes that are linked in SceneControl
  1324. meta = return_readnodes("layer_version_" + str(c))
  1325. node = nuke.toNode(str(meta))
  1326. if node is not None:
  1327. if node.metadata() != {}:
  1328. for k, v in node.metadata().iteritems():
  1329. # print (k > v)
  1330. if k == "exr/DRR_Scene":
  1331. metadata[layername + "_Scene"] = v
  1332. if k == "exr/DRR_Shader":
  1333. metadata[layername + "_Shader"] = v
  1334. if k == "exr/DRR_FXAssembly":
  1335. metadata[layername + "_FXAssembly"] = v
  1336. else:
  1337. print ("SceneControl: No Metadata availible")
  1338. else:
  1339. # should not be included in publish
  1340. pass
  1341. """
  1342. publish["nukescript"] = nukescript
  1343. # //hades/p/_projekte/DRR/02_Shots/SEQ_0200/SHOT_0200_0010/04_Lighting/02_work/nuke/lighting/
  1344. publish["sequence"] = sequence
  1345. # 0160
  1346. publish["shot"] = shot
  1347. # 0040
  1348. publish["cut_in"] = frameCutIn
  1349. # 1009
  1350. publish["cut_out"] = frameCutOut
  1351. # 1109
  1352. publish["precomp_cut_in"] = precomp_cut_in
  1353. # 1009
  1354. publish["precomp_cut_out"] = precomp_cut_out
  1355. # 1009
  1356. publish["comment"] = comment
  1357. # "My Comment\nAnother comment.\nYet another comment."
  1358. publish["shortname"] = shortname
  1359. # "ms"
  1360. publish["layer"] = layer
  1361. # {"CHAR": "011", "VOL": "011", "DUS": "009", "ENV": "011"}
  1362. publish["skip_copy_layers"] = skip_copy_layers
  1363. # ("CHAR","ENV")
  1364. publish["metadata"] = layer
  1365. # {"CHAR_Scene": "/path/to/desertRuins_MOD_v037.003.json", "CHAR_Shader": "/path/to/desertRuins_MOD_v037.003.shdAssembly.json", "CHAR_FXAssembly": "/path/to/FXAssembly"}
  1366. publish["precomp_dir"] = precomp_dir
  1367. # //hades/p/_projekte/DRR/02_Shots/SEQ_0160/SHOT_0160_0040/04_Lighting/02_work/nuke/lighting/render/SHOT_0160_0040_LIG_v001
  1368. publish["email_recipients"] = ["martin@saechsinger.de"]
  1369. """
  1370. save_script(publish=True)
  1371. # nukescript
  1372. nukescript = nuke.Root()["name"].getValue()
  1373. # prepare publish dict
  1374. publish["nukescript"] = nukescript
  1375. publish["sequence"] = sequence
  1376. publish["cut_in"] = frameCutIn
  1377. publish["cut_out"] = frameCutOut
  1378. publish["shot"] = shot
  1379. publish["comment"] = comment
  1380. publish["shortname"] = shortname
  1381. publish["layer"] = layer
  1382. publish["skip_copy_layers"] = skip_copy_layers
  1383. publish["precomp_dir"] = precomp_dir
  1384. publish["metadata"] = metadata
  1385. publish["eye"] = eye
  1386. if studioFunkRender:
  1387. publish["precomp_cut_in"] = precompframeCutIn
  1388. publish["precomp_cut_out"] = precompframeCutOut
  1389. # save script (scene control will get deleted)
  1390. # do the publish
  1391. if debug == 1.0:
  1392. reload(publisher)
  1393. print ("SceneControl: ____Test Publish:____")
  1394. for k, v in publish.items(): print (k, '>', v)
  1395. else:
  1396. reload(publisher)
  1397. for k, v in publish.items(): print (k, '>', v)
  1398. publisher.Lighting(**publish).publish()
  1399. return None
  1400. def return_readnodes(layername):
  1401. nodes = nuke.allNodes()
  1402. for n in nodes:
  1403. if n.Class() == "Read":
  1404. filepath = n.knob("file").getValue()
  1405. if layername in filepath:
  1406. return n.name()
  1407. return None
  1408. def create_readnode_old(c, autoconnect=None):
  1409. # TODO: create just one function for read, deep read and cryptomatte
  1410. n = nuke.thisNode()
  1411. k = n.knobs()
  1412. layer = n.knob("layer_name_" + str(c)).getValue()
  1413. a = "layer_version_" + str(c)
  1414. version = "v[format %%03d [value SceneControl.%s]]" % a
  1415. # replace [ASSETVERSION] with version of SceneControl
  1416. # Read
  1417. path = k["output_path"].getText()
  1418. output = k["output_file"].getText()
  1419. path = path.replace("LAYERVERSION", str(version))
  1420. path = path.replace("\\", "/")
  1421. output = output.replace("LAYERVERSION", str(version))
  1422. path = path.replace("LAYER", str(layer))
  1423. output = output.replace("LAYER", str(layer))
  1424. file = "%s/%s" % (path, output)
  1425. k["eval_helper"].setValue(file)
  1426. checkfile = k["eval_helper"].evaluate()
  1427. checkfile = checkfile.replace("\\", "/")
  1428. # create Read __________________________________________________
  1429. read = nuke.nodes.Read()
  1430. read.setName(layer)
  1431. read["file"].setValue(file)
  1432. missing = k["missing_frames"].getText()
  1433. if missing == "error":
  1434. read["on_error"].setValue(0)
  1435. elif missing == "black":
  1436. read["on_error"].setValue(1)
  1437. elif missing == "checkerboard":
  1438. read["on_error"].setValue(2)
  1439. elif missing == "nearest frame":
  1440. read["on_error"].setValue(3)
  1441. read["first"].setExpression("[value SceneControl.fStart]")
  1442. read["origfirst"].setExpression("[value SceneControl.fStart]")
  1443. read["last"].setExpression("[value SceneControl.fEnd]")
  1444. read["origlast"].setExpression("[value SceneControl.fEnd]")
  1445. read["label"].setValue("scnCtrl")
  1446. # position Read
  1447. if autoconnect is None:
  1448. # connect to selectedNode
  1449. try:
  1450. selectedNode = nuke.selectedNode()
  1451. except:
  1452. selectedNode = None
  1453. if selectedNode is not None:
  1454. selectedNode.setInput(0, read)
  1455. read.setXYpos(selectedNode.xpos(), selectedNode.ypos() - 150)
  1456. else:
  1457. # connect to dots with starts with layer name
  1458. dot = find_node_by_type(layer, "Dot")
  1459. if dot is not None:
  1460. dot.setInput(0, read)
  1461. read.setXYpos(dot.xpos() - 37, dot.ypos() - 150)
  1462. else:
  1463. pass
  1464. dot = None
  1465. return
  1466. def create_deepreadnode_old(c, autoconnect=None):
  1467. n = nuke.thisNode()
  1468. k = n.knobs()
  1469. layer = n.knob("layer_name_" + str(c)).getValue()
  1470. a = "layer_version_" + str(c)
  1471. version = "v[format %%03d [value SceneControl.%s]]" % a
  1472. # replace [ASSETVERSION] with version of SceneControl
  1473. # DeepRead __________________________________________________
  1474. path = k["output_path"].getText()
  1475. output = k["deep_output_file"].getText()
  1476. path = path.replace("LAYERVERSION", str(version))
  1477. path = path.replace("\\", "/")
  1478. output = output.replace("LAYERVERSION", str(version))
  1479. path = path.replace("LAYER", str(layer))
  1480. output = output.replace("LAYER", str(layer))
  1481. deep_subfolder = k["deep_subfolder"].getText()
  1482. if not deep_subfolder:
  1483. file = "%s/%s" % (path, output)
  1484. else:
  1485. file = "%s/%s/%s" % (path, deep_subfolder, output)
  1486. k["eval_helper"].setValue(file)
  1487. checkfile = k["eval_helper"].evaluate()
  1488. checkfile = checkfile.replace("\\", "/")
  1489. # create DeepRead
  1490. read = nuke.nodes.DeepRead()
  1491. read.setName(layer + "_Deep")
  1492. read["file"].setValue(file)
  1493. missing = k["missing_frames"].getValue()
  1494. if missing == "error":
  1495. read["on_error"].setValue(0)
  1496. elif missing == "black":
  1497. read["on_error"].setValue(1)
  1498. elif missing == "checkerboard":
  1499. read["on_error"].setValue(2)
  1500. elif missing == "nearest frame":
  1501. read["on_error"].setValue(3)
  1502. read["on_error"].setValue(1)
  1503. read["first"].setExpression("[value SceneControl.fStart]")
  1504. read["origfirst"].setExpression("[value SceneControl.fStart]")
  1505. read["last"].setExpression("[value SceneControl.fEnd]")
  1506. read["origlast"].setExpression("[value SceneControl.fEnd]")
  1507. read["label"].setValue("scnCtrl")
  1508. # position Deep Read
  1509. if autoconnect is None:
  1510. # connect to selectedNode
  1511. try:
  1512. selectedNode = nuke.selectedNode()
  1513. except:
  1514. selectedNode = None
  1515. if selectedNode is not None:
  1516. read.setXYpos(selectedNode.xpos() - 37, selectedNode.ypos() - 25)
  1517. else:
  1518. # connect to dots with starts with layer name
  1519. dot = find_node_by_type(layer + "_Deepread", "Dot")
  1520. if dot is not None:
  1521. dot.setInput(0, read)
  1522. read.setXYpos(dot.xpos() - 50, dot.ypos() - 150)
  1523. else:
  1524. pass
  1525. dot = None
  1526. return
  1527. def return_highest_layer_version():
  1528. n = nuke.thisNode()
  1529. k = n.knobs()
  1530. # gather Layers and versions to publish (exclude flagged Layers)
  1531. layernum = k["layerNum"].getValue()
  1532. num = int(layernum)
  1533. maximum = 1
  1534. for c in range(1, num + 1, 1):
  1535. value = n.knob("layer_version_" + str(c)).getValue()
  1536. if value > maximum:
  1537. maximum = value
  1538. print ("SceneControl: Highest Version is: %s" % int(maximum))
  1539. return int(maximum)
  1540. def debugQuery():
  1541. sceneControl = getSceneControl()
  1542. k = sceneControl.knobs()
  1543. # element
  1544. element = k['element'].value()
  1545. if element is None or len(element)==0:
  1546. element = 'None'
  1547. # info
  1548. info = k['info'].value()
  1549. if info is None or len(info)==0:
  1550. info = 'None'
  1551. print('SceneControl: Debug kenv query:')
  1552. print('PROJECT: ' + os.environ['PROJECT'])
  1553. print('SEQUENCE: ' + k['sequence'].value())
  1554. print('SHOT: ' + k['shot'].value())
  1555. print('DEPT: ' + k['dept'].value())
  1556. print('TASK: ' + k['task'].value())
  1557. print('MAJOR_VERSION: ' + str(int(k['major_version'].value())))
  1558. print('MINOR_VERSION: ' + str(int(k['minor_version'].value())))
  1559. print('ELEMENT: ' + element)
  1560. print('INFO: ' + info)
  1561. print('USER: ' + k['user'].value())
  1562. print('EXT: exr')
  1563. print('APP_ID: nuke')
  1564. return
  1565. # deprecated
  1566. def load_precomp():
  1567. major = nuke.thisNode().knob("major_version").getValue()
  1568. major = "v" + str(int(major)).zfill(3)
  1569. n = nuke.thisNode()
  1570. k = n.knobs()
  1571. path = k["comp_output_path"].getText()
  1572. path = path.replace("MAJORVERSION", str(major))
  1573. output = k["comp_output_file"].getText()
  1574. output = output.replace("MAJORVERSION", str(major))
  1575. path = path.replace("\\", "/")
  1576. file = "%s/%s" % (path, output)
  1577. # dance the resolve dance
  1578. k["precomp_output"].setValue(file)
  1579. precomp = k["precomp_output"].evaluate()
  1580. precomp = precomp.replace("\\", "/")
  1581. sub = precomp.split(".")[-2]
  1582. precomp = precomp.replace(sub, "####")
  1583. # create the read file
  1584. read = nuke.nodes.Read()
  1585. read.setName("Precomp")
  1586. read["file"].setValue(precomp)
  1587. read["first"].setExpression("[value SceneControl.fStart]")
  1588. read["origfirst"].setExpression("[value SceneControl.fStart]")
  1589. read["last"].setExpression("[value SceneControl.fEnd]")
  1590. read["origlast"].setExpression("[value SceneControl.fEnd]")
  1591. try:
  1592. selectedNode = nuke.selectedNode()
  1593. except:
  1594. selectedNode = None
  1595. if selectedNode is not None:
  1596. read.setXYpos(selectedNode.xpos() + 100, selectedNode.ypos())
  1597. return None
  1598. def create_writenode():
  1599. major = nuke.thisNode().knob("major_version").getValue()
  1600. major = "v" + str(int(major)).zfill(3)
  1601. write = nuke.nodes.Write()
  1602. write.setName("Precomp")
  1603. n = nuke.thisNode()
  1604. k = n.knobs()
  1605. path = k["comp_output_path"].getText()
  1606. # path = path.replace("MAJORVERSION", str(major))
  1607. output = k["comp_output_file"].getText()
  1608. # output = output.replace("MAJORVERSION", str(major))
  1609. path = path.replace("\\", "/")
  1610. file = "%s/%s" % (path, output)
  1611. write["file"].setValue(file)
  1612. write["views"].setValue("left")
  1613. write["file_type"].setValue("exr")
  1614. write["create_directories"].setValue(1)
  1615. write["metadata"].setValue(4)
  1616. try:
  1617. selectedNode = nuke.selectedNode()
  1618. except:
  1619. selectedNode = None
  1620. if selectedNode is not None:
  1621. write.setInput(0, selectedNode)
  1622. write.setXYpos(selectedNode.xpos(), selectedNode.ypos() + 66)
  1623. return
  1624. def remove_scnctrl_reads(node):
  1625. nodes = nuke.allNodes()
  1626. for n in nodes:
  1627. if n.Class() == "Read" or n.Class() == "DeepRead":
  1628. s = n.knob("label").getValue()
  1629. if s.startswith("scnCtrl"):
  1630. nuke.delete(n)
  1631. else:
  1632. pass
  1633. return