/
readMyScript.py
405 lines (356 loc) · 10.7 KB
/
readMyScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import nuke
import nukescripts
from nukescripts import *
import json
########################################################################
#### PANEL ####
########################################################################
class Rms(nukescripts.PythonPanel):
def __init__(self):
nukescripts.PythonPanel.__init__( self, 'readMyScript', 'com.romainbouvard.Rms')
### MAIN UI ###
self.addKnob(nuke.PyScript_Knob("convert all Nodes in Black", "allBlack", 'readMyScript.Rms.allBlack()'))
self.addKnob(nuke.PyScript_Knob("back to default", "Clear",'readMyScript.Rms.clear()'))
self.addKnob(nuke.Text_Knob("divName","",""))
#Convert to Selection:
self.addKnob(nuke.PyScript_Knob("convert as a Selection", 'convertToSelection', 'readMyScript.Rms.convertToSelection()'))
self.addKnob(nuke.Text_Knob("divName","",""))
#Search by Category:
#Class
self.addKnob(nuke.PyScript_Knob("search by Class", 'Class', 'readMyScript.Rms.searchClass()'))
self.searchClassID = nuke.String_Knob('')
self.searchClassID.clearFlag(nuke.STARTLINE)
self.addKnob(self.searchClassID)
#Name
self.searchNameBt = (nuke.PyScript_Knob("Search by Name", 'Name', 'readMyScript.Rms.searchName()'))
self.searchNameBt.setFlag(nuke.STARTLINE)
self.addKnob(self.searchNameBt)
self.searchNameID = nuke.String_Knob('')
self.searchNameID.clearFlag(nuke.STARTLINE)
self.addKnob(self.searchNameID)
self.addKnob(nuke.Text_Knob("divName","",""))
#Channel Selection:
self.addKnob(nuke.PyScript_Knob("list Channels in Script ", 'listChannel', 'readMyScript.Rms.listChannel()'))
self.addKnob(nuke.PyScript_Knob("Nodes more than RGBA", 'not RGBA', 'readMyScript.Rms.notRGBA()'))
self.addKnob(nuke.PyScript_Knob("Filter via a maskChannel", 'masked Channels', 'readMyScript.Rms.maskChannel()'))
self.addKnob(nuke.Text_Knob("divName","",""))
#OverSize Bbox:
self.addKnob(nuke.PyScript_Knob("Bbox compare to Input Size", 'oversizeBbox', 'readMyScript.Rms.oversizeBbox()'))
self.slider = nuke.Double_Knob('')
self.slider.setRange(1,2)
self.slider.setValue(1.25)
self.slider.clearFlag(nuke.STARTLINE)
self.addKnob(self.slider)
self.addKnob(nuke.Text_Knob("divName","",""))
#Channel Filter:
self.addKnob(nuke.PyScript_Knob("apply on filter All, e.g. Blur", 'filterAll', 'readMyScript.Rms.filterAll()'))
self.addKnob(nuke.PyScript_Knob("mixKnob not default", 'mixKnob', 'readMyScript.Rms.mixKnob()'))
self.addKnob(nuke.Text_Knob("divName","",""))
#Input / Output:
self.addKnob(nuke.PyScript_Knob("Hidden Input", 'inputHide', 'readMyScript.Rms.inputHide()'))
self.addKnob(nuke.PyScript_Knob("no Output", 'noOutput', 'readMyScript.Rms.noOutput()'))
self.addKnob(nuke.PyScript_Knob("B Branch", 'mainInput', 'readMyScript.Rms.mainInput()'))
self.addKnob(nuke.Text_Knob("divName","",""))
#Animation/Tag:
self.addKnob(nuke.PyScript_Knob("Animated Nodes", 'Animated', 'readMyScript.Rms.AnimationNodes()'))
self.addKnob(nuke.PyScript_Knob("tag", 'tag', 'readMyScript.Rms.tag()'))
self.addKnob(nuke.PyScript_Knob("Disabled Nodes", 'Disable', 'readMyScript.Rms.Disable()'))
self.addKnob(nuke.Text_Knob("divName","",""))
# dictionaries and colors:
self.dicOrigin = {}
self.dicModif = {}
self.darkColor = self.hexColor(0.25,0.25,0.25)
self.goodColor = self.hexColor(0,1,0)
# CORE TOOLS
# Structure: /1-Edit(value) /2-Store-Restore /3-ColorList
def hexColor(self,r,g,b):
value = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1),16)
return value
def edit (self,value):
self.value = value
if value == 0:
self.store()
self.colorList()
else:
self.restore()
def store(self):
for i in nuke.allNodes():
color = i.knob('tile_color').value()
name = i.name()
self.dicOrigin[name] = color
return self.dicOrigin
def restore(self):
for i in nuke.allNodes():
name = i.name()
color= i.knob('tile_color').value()
i.knob('tile_color').setValue(self.dicOrigin.get(name, color))
self.dicOrigin.clear()
self.dicModif.clear()
return self.dicOrigin, self.dicModif
def colorList(self):
# Recolor The node
for i in nuke.allNodes():
name = i.name()
color = i.knob('tile_color').value()
i.knob('tile_color').setValue(self.dicModif.get(name, color))
# UTILITIES
# Structure: /1-CleanData /2-SearchData /3-StoreData /4-RevealData
def allBlack(self):
#clean Data
self.edit(1)
#search Data
for i in nuke.allNodes():
#self.otherNodes.append(i)
name = i.name()
self.dicModif[name] = self.darkColor
#Store Data + Reveal Data
self.edit(0)
def clear(self):
self.edit(1)
def convertToSelection(self):
for i in nuke.allNodes():
name = i.name()
if self.dicModif[name] != self.darkColor:
i.knob("selected").setValue(True)
#clean Data
self.edit(1)
def searchClass(self):
#Restore Data
self.edit(1)
#Find Data
searchClass = self.searchClassID.value()
for i in nuke.allNodes():
name = i.name()
if searchClass in name:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def searchName(self):
#Restore Data
self.edit(1)
#Find Data
searchName = self.searchNameID.value()
for i in nuke.allNodes():
name = i.name()
if searchName in name:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def listChannel(self):
self.edit(1)
L = nuke.layers()
p = nuke.Panel( 'all Channels' )
p.addEnumerationPulldown( 'mySelection', ' '.join( L ) )
if not p.show():
return
else:
layer = p.value('mySelection')
#for Loop in AllNodes
if layer:
for i in nuke.allNodes():
name = i.name()
channels = i.channels()
allLayers = list( set([c.split('.')[0] for c in channels]) )
if layer in allLayers:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def notRGBA(self):
self.edit(1)
# For Channels:
rgba = ['rgba.red', 'rgba.green', 'rgba.blue', 'rgba.alpha']
rgb = ['rgba.red', 'rgba.green', 'rgba.blue']
alpha = ['rgba.alpha']
empty = []
allChannels = [rgba] + [rgb] + [alpha] + [empty]
#Find Data
for i in nuke.allNodes():
name = i.name()
channels = i.channels()
layers = list( set([c.split('.')[0] for c in channels]) )
if not channels in allChannels:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def maskChannel(self):
self.edit(1)
for i in nuke.allNodes():
name = i.name()
if i.knob('maskChannelInput'):
if i['maskChannelInput'].value() != 'none':
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def filterAll(self):
self.edit(1)
for i in nuke.allNodes():
name = i.name()
if i.knob('channel'):
if i['channel'].value() == 'all':
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def oversizeBbox(self):
self.edit(1)
#Find Percent Slider
percentValue = self.slider.value()
# For loop in allNodes
for i in nuke.allNodes():
name = i.name()
if i.bbox().w() > percentValue*i.width() or i.bbox().h() > percentValue*i.height():
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def mixKnob(self):
self.edit(1)
for i in nuke.allNodes():
name = i.name()
if i.knob('mix'):
x = i.knob('mix')
value = x.value()
if value != 1:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def inputHide(self):
self.edit(1)
for n in nuke.allNodes():
name = n.name()
if n.knob('hide_input'):
if n.Class() != 'Viewer':
x = n.knob('hide_input')
value = x.value()
if value == 0:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.goodColor
n.setSelected(1)
dependenciesOfWrite = nuke.dependencies([n])
for d in dependenciesOfWrite:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Add Viewer Nodes
viewer = nuke.allNodes('Viewer')
for i in viewer:
name = i.name()
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def noOutput(self):
self.edit(1)
for a in nuke.allNodes():
name = a.name()
x = a.dependent()
y = a.dependencies()
if y == []:
self.dicModif[name] = self.darkColor
else:
if a.inputs():
if x == []:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.darkColor
#Add Viewer Nodes
viewer = nuke.allNodes('Viewer')
for i in viewer:
name = i.name()
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def AnimationNodes(self):
self.edit(1)
def isAnimated(node):
return bool(int(node['indicators'].value()) & 1)
for n in nuke.allNodes():
name = n.name()
if isAnimated(n) == True:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def tag(self):
self.edit(1)
for i in nuke.allNodes():
name = i.name()
if name[:3] == "tag":
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def mainInput(self):
def climb(node):
#Start Node:
thisNode = [node]
# find if dependency exist and add thisNode to the list:
for n in thisNode:
input = n.input(0)
goodNodes.append(n)
# Loop if dependency still exist:
if input:
climb(input)
return goodNodes
self.edit(1)
a = nuke.selectedNode()
if not a == None:
goodNodes = []
climb(a)
#Recolor D
if goodNodes != None:
for i in nuke.allNodes():
name = i.name()
self.dicModif[name] = self.darkColor
for i in goodNodes:
name = i.name()
self.dicModif[name] = self.goodColor
else:
nuke.message('please select a node')
#Store Data
self.edit(0)
def Disable(self):
self.edit(1)
for i in nuke.allNodes():
name = i.name()
if i.knob('disable'):
select = i['disable'].value()
if select:
self.dicModif[name] = self.goodColor
else:
self.dicModif[name] = self.darkColor
else:
self.dicModif[name] = self.darkColor
#Store Data
self.edit(0)
def add_RmsPanel():
global Rms
Rms = Rms()
return Rms.addToPane()
paneMenu = nuke.menu( 'Pane' )
paneMenu.addCommand( 'Rms', add_RmsPanel )
nukescripts.registerPanel('com.romainbouvard.Rms', add_RmsPanel )