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_LinkedStamp.py
executable file
·350 lines (241 loc) · 9.82 KB
/
mod_LinkedStamp.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
"""
Connect to a node with hidden inputs to keep script logically clean
"""
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import nuke, nukescripts
import platform
import os
from Qt import QtWidgets, QtGui, QtCore
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '3.4'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "LinkedStamp v%s" % __VERSION__
def _version_():
ver="""
version 3.4
- add deep data output check
- adding marking function
- add UI pop up when launch with no node selected
- use nuke built-in setName()
- disable knobChanged callback
version 3.3
- added shortcut to reconnect
version 3.2
- Change Deep node linkStamp from Dot to NoOp
- Dynamically change knobChanged() effected Class
- remove node name from autolabel
- change note_font when disconnected
version 3.1
- if topnode is a roto node, change tile_color to match
- add a PyScript button, copy current LinkedStamp and its input
- If selected node is `Deep`, use `Dot` node
version 3.0
- added Button, Show Parent Node in DAG
- Change name to "LinkedStamp"
version 2.1
- added Python_button, connect to a node listed in Label
version 2.0
- added Callback, label changes when input changed
version 0
- Postage Stamp with hidden inputs
"""
return ver
# ------------------------------------------------------------------------------
# Globale Variable
# ------------------------------------------------------------------------------
MARKER_NAME = 'tb_linkedstamp_marker'
MARKED_LABEl = '\nLinkedStamp Marked'
BASE_NAME = 'LinkedStamp'
# ------------------------------------------------------------------------------
# Main Functions
# ------------------------------------------------------------------------------
def LinkedStamp(mode='set'):
"""Main function
mode='set': creating link (default)
mode='reconnect': reconnect
mode='marking': marking a node for LinkedStamp to connect to
"""
if mode == 'set':
# Nothing is selected
if not len(nuke.selectedNodes()): node_parent = FindMarker().run()
else: node_parent = nuke.selctedNode()
# User Cancels or Select A Marker
if node_parent == None: print("User Cancelled")
else:
node_parent_nam = node_parent.name()
node_slave = None
if isOutputDeep(node_parent):
node_slave = nuke.nodes.NoOp()
else:
node_slave = nuke.nodes.PostageStamp()
node_slave['postage_stamp'].setValue(False) if node_parent.Class().startswith('Roto') else node_slave['postage_stamp'].setValue(True)
stpMarking(node_parent)
node_slave.setInput(0, node_parent)
node_slave['hide_input'].setValue(1)
node_slave['label'].setValue('linked to: [value tx_nodename]')
node_slave['tile_color'].setValue(stpColor(node_parent))
node_slave.setName(BASE_NAME)
node_slave.setXYpos(node_parent.xpos()+75,node_parent.ypos()+25)
# Add User knobs
py_cmd_restore= "n=nuke.thisNode()\nn.setInput(0, nuke.toNode(n['connect'].value()))"
py_cmd_orig = "origNode = nuke.thisNode().input(0);\
origXpos = origNode.xpos();\
origYpos = origNode.ypos();\
nuke.zoom(2, [origXpos,origYpos]);\
nuke.thisNode()['selected'].setValue(False);\
origNode['selected'].setValue(True);\
nuke.show(origNode)"
py_cmd_copy = "origNode = nuke.thisNode().input(0);\
filter(lambda n: n.setSelected(False), nuke.selectedNodes());\
nuke.thisNode().setSelected(True);\
nuke.nodeCopy('%clipboard%');\
new_node = nuke.nodePaste('%clipboard%');\
new_node.setInput(0, origNode);\
new_node.setXpos(nuke.thisNode().xpos()+120)"
k_tab = nuke.Tab_Knob("LinkedStamp")
k_text = nuke.String_Knob('tx_nodename', "Set Input to: ")
k_enable = nuke.Boolean_Knob('ck_enable', "Enable")
k_setInput = nuke.PyScript_Knob('link', "Set Input", py_cmd_restore)
k_showParent = nuke.PyScript_Knob('orig', "Show Parent Node", py_cmd_orig)
k_copy = nuke.PyScript_Knob('copy', "Copy this Node", py_cmd_copy)
k_connect = nuke.String_Knob('connect','toConnect',node_parent_nam)
k_setInput.setFlag(nuke.STARTLINE)
k_text.setEnabled(False)
k_enable.clearFlag(nuke.STARTLINE)
k_showParent.clearFlag(nuke.STARTLINE)
k_copy.clearFlag(nuke.STARTLINE)
k_connect.setFlag(nuke.INVISIBLE)
node_slave.addKnob(k_tab)
node_slave.addKnob(k_text)
node_slave.addKnob(k_enable)
node_slave.addKnob(k_setInput)
node_slave.addKnob(k_showParent)
node_slave.addKnob(k_copy)
node_slave.addKnob(k_connect)
k_text.setValue(node_slave['connect'].value())
k_setInput.setTooltip("Taking the node name from label and connect")
k_showParent.setTooltip("Show parent node in DAG")
k_copy.setTooltip("Copy this node with its inputs")
node_slave['knobChanged'].setValue('k=nuke.thisKnob()\nif k.name()=="ck_enable":\n\tnuke.thisNode()["tx_nodename"].setEnabled(k.value())')
node_slave['autolabel'].setValue("('Disconnected from\\n' if len(nuke.thisNode().dependencies())<=0 else 'Linked to\\n')+nuke.thisNode()['tx_nodename'].value()")
elif mode=='reconnect':
node_parents = nuke.selectedNodes()
for n in node_parents:
if n['LinkedStamp'].value():
n.setInput(0, nuke.toNode(n['connect'].value()))
elif mode =='marking':
for n in nuke.selectedNodes():
stpMarking(n)
# ------------------------------------------------------------------------------
# Supporting Functions
# ------------------------------------------------------------------------------
def stpRename(BASE_NAME):
"""Replaced with built-in node.setName()"""
"""Rename LinkedStamp to avoid conflict"""
all_stp = [n.name() for n in nuke.allNodes() if BASE_NAME in n.name()]
if len(all_stp) > 0:
stp_max = max(all_stp)
else:
stp_max = BASE_NAME + "1"
new_index = int(stp_max.strip(BASE_NAME))+1
new_name = BASE_NAME+str(new_index)
return new_name
def stpColor(node_parent):
"""Find topnode Class and set tile_color"""
node_top_name = nuke.tcl("full_name [topnode %s]" % node_parent.name())
node_top_class = nuke.toNode(node_top_name).Class()
node_color = 0
if node_top_class.startswith('Roto'):
node_color = 1908830719 # system roto class color
elif node_top_class.startswith('Deep'):
node_color = 24831 # system deep class color
else:
node_color = 12040191 # pascal cyan
return node_color
def stpMarking(node_parent):
"""mark node to be recongnized by LinkedStamp
(called everytime in set mode before connect)
@node: (obj) parent node that is initially selected
"""
if not node_parent.knob(MARKER_NAME):
k_mark = nuke.Tab_Knob(MARKER_NAME,'LinkedStamp Marker')
k_mark_label = nuke.Text_Knob('tx_linkedstamp_marker', "","This node is marked by LinkedStamp")
node_parent.addKnob(k_mark)
node_parent.addKnob(k_mark_label)
node_parent['label'].setValue(node_parent['label'].value()+MARKER_NAME)
print("%s LinkedStamp Marked" % node_parent.name())
else:
print("New LinkedStamp from: %s" % node_parent.name())
def isOutputDeep(node):
"""check if node is outputing deep data
@node: (obj) root node of the tree
return: (bool) True if is deep, False otherwise
"""
outputdeep=None
try: node.deepSampleCount(0,0); outputdeep = True
except: outputdeep = False
return outputdeep
# ------------------------------------------------------------------------------
# UI
# ------------------------------------------------------------------------------
class FindMarker(QtWidgets.QDialog):
"""UI popup to find and connect a LinkedStamp marked node
return: (obj) parent node to connect
"""
def __init__(self):
super(FindMarker, self).__init__()
self.parent_node=None
self.marker_node = [n.name() for n in nuke.allNodes() if n.knob(MARKER_NAME)]
self.label = QtWidgets.QLabel("<b>Find LinkStamp Marker</b>")
self.box_comboBox = QtWidgets.QComboBox()
self.box_comboBox.addItems(self.marker_node)
# self.box_comboBox.setEditable(True)
self.btn_confirm = QtWidgets.QPushButton('LINK')
self.btn_confirm.clicked.connect(self.onConfirm)
self.layout = QtWidgets.QVBoxLayout()
self.setLayout(self.layout)
self.layout.addWidget(self.label)
self.layout.addWidget(self.box_comboBox)
self.layout.addWidget(self.btn_confirm)
self.layout.setAlignment(QtCore.Qt.AlignCenter)
self.setWindowTitle("Set LinkedStamp")
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
def run():
self.move(QtGui.QCursor.pos()+QtCore.QPoint(self.frameGeometry().width()/-2,self.frameGeometry().height()/-2))
self.box_comboBox.setFocus()
self.exec_()
return self.parent_node
def onConfirm(self):
self.parent_node = nuke.toNode(self.box_comboBox.currentText())
self.close()
# ------------------------------------------------------------------------------
# Callbacks
# ------------------------------------------------------------------------------
def inputUpdate():
n = nuke.thisNode()
k = nuke.thisKnob()
if n.Class() in ['PostageStamp', 'NoOp']:
if k.name() == "inputChange":
if len(n.dependencies())<=0:
n['note_font'].setValue('bold')
n['note_font_color'].setValue(3623878911) # Dark Red
n['hide_input'].setValue(False)
print '%s disconnected' % n.name()
elif len(n.dependencies())>0:
n['connect'].setValue(n.dependencies()[0].name())
n['tx_nodename'].setValue(n['connect'].value())
n['note_font'].setValue('')
n['note_font_color'].setValue(0)
n['hide_input'].setValue(True)
print '%s connected' % n.name()
elif k.name() == 'tx_nodename':
n['connect'].setValue(k.value())
# nuke.addKnobChanged(inputUpdate, nodeClass='PostageStamp')
# nuke.addKnobChanged(inputUpdate, nodeClass='NoOp')