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_UtilSampler.py
100 lines (59 loc) · 2.13 KB
/
mod_UtilSampler.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
'''
Module to Sample utility passes from viewer
'''
#------------------------------------------------------------------------------
#-Module Import
#------------------------------------------------------------------------------
import nuke, nukescripts
import platform
import os
#------------------------------------------------------------------------------
#-Header
#------------------------------------------------------------------------------
__VERSION__ = '1.0'
__OS__ = platform.system()
__AUTHOR__ = "Tianlun Jiang"
__WEBSITE__ = "jiangovfx.com"
__COPYRIGHT__ = "copyright (c) %s - %s" % (__AUTHOR__, __WEBSITE__)
__TITLE__ = "UtilSampler v%s" % __VERSION__
def _version_():
ver='''
version 1.0
- Features
'''
return ver
#-------------------------------------------------------------------------------
#-Main Function
#-------------------------------------------------------------------------------
def UtilSampler(aov):
"""Sample aov passe of a active viewer and its input
Copy to xyz translate knob with node selected, print out values otherwise
@aov: (str) name of the aov layer to sample
"""
node_viewer = nuke.activeViewer().node()
active_input = nuke.ViewerWindow.activeInput(nuke.activeViewer())
node_sample = node_viewer.input(active_input)
bbox_sample = node_viewer['colour_sample_box']
bbox = [bbox_sample.x(), bbox_sample.y()*aspect]
viewer_format = [node_sample.width(), node_sample.height()]
dim = [d/2 for d in viewer_format]
aspect = float(dim[0])/float(dim[1])
coord = [
int(round(bbox[0]*dim[0]+dim[0])),
int(round(bbox[1]*dim[1]+dim[1]))
]
if aov in nuke.layers(node_sample):
sample_value = [
nuke.sample(node_sample, aov+'.red', coord[0], coord[1], 1, 1),
nuke.sample(node_sample, aov+'.green', coord[0], coord[1], 1, 1),
nuke.sample(node_sample, aov+'.blue', coord[0], coord[1], 1, 1)
]
print("Sample %s: %s" % (node_sample.name(), sample_value))
if nuke.selectedNodes() != []:
node = nuke.selectedNode()
k = node.knob('translate')
if k:
if k.Class() == 'XYZ_Knob':
k.setValue(sample_value)
else:
print("Layer (%s) does not exist" % aov)