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 66KB

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