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_DotCamConnect.py
executable file
·191 lines (114 loc) · 4.37 KB
/
mod_DotCamConnect.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
'''
Dot node to connect a camera
'''
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import platform
import os
from Qt import QtWidgets, QtGui, QtCore
import nuke, nukescripts
import logging
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '2.1'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "DotCamConnect v%s" % __VERSION__
def _version_():
ver='''
version 2.1
- directly connect if only one camera in the script
- Redorder codes
version 2.0
- add button to open input node property panel
version 1.0
- Find A Camera nodes in nuke
- List names of the ndoes in a menu
- Select the node and Connect!
- Hide the input, set the color to red and put the Camera Node name to Dot node's label
'''
return ver
# ------------------------------------------------------------------------------
#-GLOBAL VARIABLE
# ------------------------------------------------------------------------------
CLASS_CAM = 'Camera2'
COL_RED = int('%02x%02x%02x%02x' % (1*255,0*255,0*255,0*255),16)
COL_WHITE = int('%02x%02x%02x%02x' % (1*255,1*255,1*255,1*255),16)
# ------------------------------------------------------------------------------
# Logging
# ------------------------------------------------------------------------------
log = logging.getLogger('kplogger')
#-------------------------------------------------------------------------------
#-Main Functions
#-------------------------------------------------------------------------------
def DotCamConnect():
# Find All the Camera nodes
node_ls_cam = [n.name() for n in nuke.allNodes(CLASS_CAM)]
node_ls_cam.sort()
sel_node_dot = nuke.selectedNodes('Dot')
sel_cam_node = get_camera(node_ls_cam)
if sel_cam_node:
# If a Dot node is selected
if sel_node_dot != [] and node_ls_cam != []:
for d in sel_node_dot:
set_node_dot(d, sel_cam_node)
return True
# if nothing is selected
if nuke.selectedNodes() == []:
node_create_dot = nuke.createNode('Dot', inpanel=False)
set_node_dot(node_create_dot, sel_cam_node)
return True
# ------------------------------------------------------------------------------
# Supporting Function
# ------------------------------------------------------------------------------
def set_node_dot(d, node_sel_cam):
"""Set Connect Function OR setting Dot Node Function"""
d['label'].setValue("\n%s" % (node_sel_cam))
d['note_font'].setValue('bold')
d['note_font_size'].setValue(24)
d['note_font_color'].setValue(COL_WHITE)
d['tile_color'].setValue(COL_RED)
d['hide_input'].setValue(True)
d.setInput(0, nuke.toNode(node_sel_cam))
# Add Show Panel Knob
cmd_ppanel = "n=nuke.thisNode()\ntry:\n\tn.input(0).showControlPanel(forceFloat=n.knob('isFloat').value())\nexcept:\n\tpass"
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)"
t_tab = nuke.Tab_Knob('t_user', "DotCamConnect")
k_showPanel = nuke.PyScript_Knob('ppanel', "Show Input Property Panel", cmd_ppanel)
k_float = nuke.Boolean_Knob('isFloat', "Floating Panel", True)
k_showCam = nuke.PyScript_Knob('orig', "Show Camera Node", cmd_orig)
k_float.clearFlag(nuke.STARTLINE)
k_float.setFlag(nuke.STARTLINE)
d.addKnob(t_tab)
d.addKnob(k_showPanel)
d.addKnob(k_float)
d.addKnob(k_showCam)
print("%s -> %s" % (d.name(), node_sel_cam))
def get_camera(node_ls_cam):
"""Prompt UI for camera selection
@node_ls_cam: (list of camera node)
return: (node) selected camera node, None if cancel or no camera in DAG
"""
node_sel_cam = None
if len(node_ls_cam) > 1:
p = nuke.Panel('Select A Camera Node to Connect')
p.addEnumerationPulldown('Cam to Connect', ' '.join(node_ls_cam))
p.addButton('Cancel')
p.addButton('Connect!')
if p.show():
node_sel_cam = p.value('Cam to Connect')
else:
node_sel_cam = None
elif len(node_ls_cam) == 1:
node_sel_cam = node_ls_cam[0]
return node_sel_cam