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_Cycling.py
196 lines (131 loc) · 4.14 KB
/
mod_Cycling.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
'''
one hotkey cycling channels and merge operations
'''
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import platform
import os
from Qt import QtWidgets, QtGui, QtCore
import nuke, nukescripts
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '2.0'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "Cycling v%s" % __VERSION__
def _version_():
ver='''
version 2.0
- merge knobChange for output channels
- add prev mode
version 1.0
- one hotkey cycling channels and merge operations
'''
return ver
#-------------------------------------------------------------------------------
#-Main Function
#-------------------------------------------------------------------------------
def Cycling(mode='regular'):
'''main fucntion
@mode='regular': often used channels/operations in merge node
@mode='all': all channels/operations in last selected node
'''
n = nuke.selectedNode()
if n == None:
nuke.message('Please select a node')
else:
if n.Class()=='Merge2':
coreCycle('op',n,mode)
else:
coreCycle('ch',n,mode)
#-------------------------------------------------------------------------------
#-Supporting Functions
#-------------------------------------------------------------------------------
def setKnob(node, knob, ls_k):
'''loop and set knob values
@n: node, obj
@knob:knob name, str
@ls_k: list of knob values, list
'''
try:
k = node[knob]
k_cur = k.value()
k_new = None
if k_cur in ls_k:
k_count = ls_k.index(k_cur)
if k_count==len(ls_k)-1:
k_new_idx = 0
elif k_count < 0:
k_new_idx = len(ls_k)
elif mode == 'regular':
k_new_idx = k_count+1
elif mode == 'prev':
k_new_idx = k_count-1
k_new = ls_k[int(k_new_idx)]
else:
k_new = ls_k[0]
k.setValue(k_new)
print("%s set to %s" % (node.name(), k_new))
except:
print("knob %s not in %s" % (knob, node.name()))
def coreCycle(knob, node, mode):
'''main cycling operation
@knob='ch': channels for nodes with channels knob
@knob='op': operation for merge node
@mode='regular': often used channels/operations in merge node
@mode='all': all channels/operations in last selected node
@mode='prev': switch to previous operation in list
@node: input node, obj
'''
if knob=='ch':
ls_ch = []
if mode == 'regular':
ls_ch = ['rgb', 'rgba', 'alpha','all']
elif mode == 'all':
# unconnected nodes will return empty list
ls_ch = nuke.layers(node) if nuke.layers(node) else ['rgb', 'rgba', 'alpha','all']
if node.Class() == 'Shuffle':
try:
ls_ch.remove('all')
except: pass
setKnob(node,'in',ls_ch)
else:
setKnob(node,'channels', ls_ch)
elif knob=='op':
ls_op = []
if mode in ['regular', 'prev']:
ls_op = ['plus', 'minus', 'mask', 'stencil', 'over', 'under', 'max', 'min', 'multiply', 'divide', 'hypot']
elif mode == 'all':
ls_op = node['operation'].values()
setKnob(node, 'operation', ls_op)
#-------------------------------------------------------------------------------
#-Callback Functions
#-------------------------------------------------------------------------------
def ch_merge_out():
"""channel output for merge node"""
n = nuke.thisNode()
k = nuke.thisKnob()
rgbOnly = [
'plus', 'minus', 'multiply', 'hypot',
'color-dodge', 'color-burn', 'average',
'geometric', 'overlay', 'soft-light',
]
if k:
if k.name() == 'operation':
if k.value() in rgbOnly:
n['output'].setValue('rgb')
else:
n['output'].setValue('rgba')
else:
if n['operation'].value() in rgbOnly:
n['output'].setValue('rgb')
else:
n['output'].setValue('rgba')
#-------------------------------------------------------------------------------
#-Adding Callbacks
#-------------------------------------------------------------------------------
nuke.addKnobChanged(ch_merge_out, nodeClass='Merge2')