This repository was archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_AOVContactSheet.py
185 lines (118 loc) · 4.94 KB
/
mod_AOVContactSheet.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
'''
Filtering chanel layers with keywords
'''
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import platform
import os
from Qt import QtWidgets, QtGui, QtCore
import nuke, nukescripts
import re
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '1.0'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "AOVContactSheet v%s" % __VERSION__
def _version_():
ver='''
version 1.0
- if a node is selected, prompt for keyword create a contactsheet group node
'''
return ver
#------------------------------------------------------------------------------
#-Main Functions
#------------------------------------------------------------------------------
def AOVContactSheet():
'''main function'''
if not nuke.selectedNode():
nuke.message("Select a node")
else:
node_xpos = nuke.selectedNode().xpos() + nuke.selectedNode().screenWidth()
node_ypos = nuke.selectedNode().ypos() + nuke.selectedNode().screenHeight()
node = create_group()
if node:
node.setXpos(node_xpos)
node.setYpos(node_ypos)
node.setInput(0, nuke.selectedNode())
filtering(node)
def button_filter():
'''filter with keywords with button pressed'''
node = nuke.thisNode()
filtering(node)
#------------------------------------------------------------------------------
#-Supporting Function
#------------------------------------------------------------------------------
def filtering(node):
'''main filtering function'''
layers_all = nuke.layers(node.dependencies(nuke.INPUTS)[0])
layers_filtered = filter_core(layers_all, node['keywords'].value())
build_remove(layers_filtered, node)
def filter_core(layers_all, search_str):
'''filter layers with user input string
@layers_all: (list of str) list of all layers
@search_str: (str) string to filter layers
return: (dict of str, int: [str,...]) filtered dict of layers'''
_layers_keep = [s for s in layers_all if re.search(search_str, s)]
_layers_remove = list(set(layers_all)-set(_layers_keep))
counter = 0
dict_remove={}
_thisList = list()
for idx, l in enumerate(_layers_remove, 1):
_thisList.append(l)
if idx % 4 == 0:
dict_remove[counter]=_thisList
_thisList=[]
counter += 1
del _thisList
return dict_remove
def build_remove(dict_remove, node):
'''rebuild Remove node everytime it's called
@dict_remove: (dict of str, int: [str,...]) filtered dict of layers
@node: (obj) node object to build
'''
CH = ['channels', 'channels2', 'channels3', 'channels4']
with node:
for r in nuke.allNodes('Remove'):
nuke.delete(r)
nukescripts.clear_selection_recursive()
nuke.toNode('Input').setSelected(True)
for k in dict_remove:
node_remove = nuke.createNode('Remove', 'operation remove', inpanel=False)
thisGroup = dict_remove[k]
node_remove['label'].setValue(', '.join(thisGroup))
for idx, l in enumerate(thisGroup):
node_remove[CH[idx]].setValue(l)
def create_group():
'''create a group node with proper nodes
return: (obj) group node object'''
user_keyword = nuke.getInput("keyword to filter", "*")
if user_keyword is not None:
node = nuke.nodes.Group()
node.setName('AOVContactSheet')
k_tab = nuke.Tab_Knob('tb_user', 'ku_AOVContactsheet')
k_key = nuke.String_Knob('keywords', "keywords", user_keyword)
k_filter = nuke.PyScript_Knob('bt_filter', "Filter", 'mod_AOVContactSheet.button_filter()')
node.addKnob(k_tab)
node.addKnob(k_key)
node.addKnob(k_filter)
node['label'].setValue('filtering: [value keywords]')
node['note_font'].setValue('Bold')
# Adding Copyright info
add_gizmo_copyright(node)
with node:
node_input = nuke.createNode('Input', 'name Input', inpanel=False)
node_crop = nuke.createNode('Crop', inpanel=False)
node_contact = nuke.createNode('LayerContactSheet', inpanel=False)
node_output = nuke.createNode('Output', 'name Output', inpanel=False)
node_crop['box'].setExpression('input.bbox.x', 0)
node_crop['box'].setExpression('input.bbox.y', 1)
node_crop['box'].setExpression('input.bbox.r', 2)
node_crop['box'].setExpression('input.bbox.t', 3)
node_contact['showLayerNames'].setValue(True)
node_crop['reformat'].setValue(True)
return node