Sin descripción
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 65KB

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