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 | class LinkAsGroup(load.LoaderPlugin):
"""Copy the published file to be pasted at the desired location"""
product_types = {"workfile", "nukenodes"}
representations = {"*"}
extensions = {"nk"}
settings_category = "nuke"
label = "Load Precomp"
order = 0
icon = "file"
color = "#cc0000"
def load(self, context, name, namespace, data):
# for k, v in context.items():
# log.info("key: `{}`, value: {}\n".format(k, v))
version_entity = context["version"]
version_attributes = version_entity["attrib"]
first = version_attributes.get("frameStart")
last = version_attributes.get("frameEnd")
colorspace = version_attributes.get("colorSpace")
# Fallback to folder name when namespace is None
if namespace is None:
namespace = context["folder"]["name"]
file = self.filepath_from_context(context).replace("\\", "/")
self.log.info("file: {}\n".format(file))
data_imprint = {
"startingFrame": first,
"frameStart": first,
"frameEnd": last,
"version": version_entity["version"]
}
# add additional metadata from the version to imprint to Avalon knob
for k in [
"frameStart",
"frameEnd",
"handleStart",
"handleEnd",
"source",
"fps"
]:
data_imprint[k] = version_attributes[k]
# group context is set to precomp, so back up one level.
nuke.endGroup()
# P = nuke.nodes.LiveGroup("file {}".format(file))
P = nuke.createNode(
"Precomp",
"file {}".format(file),
inpanel=False
)
# Set colorspace defined in version data
self.log.info("colorspace: {}\n".format(colorspace))
P["name"].setValue("{}_{}".format(name, namespace))
P["useOutput"].setValue(True)
with P:
# iterate through all nodes in group node and find pype writes
writes = [n.name() for n in nuke.allNodes()
if n.Class() == "Group"
if get_avalon_knob_data(n)]
if writes:
# create panel for selecting output
panel_choices = " ".join(writes)
panel_label = "Select write node for output"
p = nuke.Panel("Select Write Node")
p.addEnumerationPulldown(
panel_label, panel_choices)
p.show()
P["output"].setValue(p.value(panel_label))
P["tile_color"].setValue(0xff0ff0ff)
return containerise(
node=P,
name=name,
namespace=namespace,
context=context,
loader=self.__class__.__name__,
data=data_imprint)
def switch(self, container, context):
self.update(container, context)
def update(self, container, context):
"""Update the Loader's path
Nuke automatically tries to reset some variables when changing
the loader's path to a new file. These automatic changes are to its
inputs:
"""
node = container["node"]
project_name = context["project"]["name"]
version_entity = context["version"]
repre_entity = context["representation"]
root = get_representation_path(repre_entity).replace("\\", "/")
# Get start frame from version data
version_attributes = version_entity["attrib"]
updated_dict = {
"representation": repre_entity["id"],
"frameEnd": version_attributes.get("frameEnd"),
"version": version_entity["version"],
"colorspace": version_attributes.get("colorSpace"),
"source": version_attributes.get("source"),
"fps": version_attributes.get("fps"),
}
# Update the imprinted representation
update_container(
node,
updated_dict
)
node["file"].setValue(root)
last_version_entity = ayon_api.get_last_version_by_product_id(
project_name, version_entity["productId"], fields={"id"}
)
# change color of node
if version_entity["id"] == last_version_entity["id"]:
color_value = "0xff0ff0ff"
else:
color_value = "0xd84f20ff"
node["tile_color"].setValue(int(color_value, 16))
self.log.info(
"updated to version: {}".format(version_entity["version"])
)
def remove(self, container):
node = container["node"]
with viewer_update_and_undo_stop():
nuke.delete(node)
|