Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Nuke: gizmo publishing error #594

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions pype/plugins/nuke/load/load_gizmo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
from avalon import api, style, io
import nuke
from avalon.nuke import lib as anlib
from avalon.nuke import containerise, update_container


class LoadGizmo(api.Loader):
"""Loading nuke Gizmo"""

representations = ["gizmo"]
families = ["gizmo"]

label = "Load Gizmo"
order = 0
icon = "dropbox"
color = style.colors.light
node_color = "0x75338eff"

def load(self, context, name, namespace, data):
"""
Loading function to get Gizmo into node graph

Arguments:
context (dict): context of version
name (str): name of the version
namespace (str): asset name
data (dict): compulsory attribute > not used

Returns:
nuke node: containerised nuke node object
"""

# get main variables
version = context['version']
version_data = version.get("data", {})
vname = version.get("name", None)
first = version_data.get("frameStart", None)
last = version_data.get("frameEnd", None)
namespace = namespace or context['asset']['name']
colorspace = version_data.get("colorspace", None)
object_name = "{}_{}".format(name, namespace)

# prepare data for imprinting
# add additional metadata from the version to imprint to Avalon knob
add_keys = ["frameStart", "frameEnd", "handleStart", "handleEnd",
"source", "author", "fps"]

data_imprint = {"frameStart": first,
"frameEnd": last,
"version": vname,
"colorspaceInput": colorspace,
"objectName": object_name}

for k in add_keys:
data_imprint.update({k: version_data[k]})

# getting file path
file = self.fname.replace("\\", "/")

# adding nodes to node graph
# just in case we are in group lets jump out of it
nuke.endGroup()

with anlib.maintained_selection():
# add group from nk
nuke.nodePaste(file)

GN = nuke.selectedNode()

GN["name"].setValue(object_name)

return containerise(
node=GN,
name=name,
namespace=namespace,
context=context,
loader=self.__class__.__name__,
data=data_imprint)

def update(self, container, representation):
"""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:

"""

# get main variables
# Get version from io
version = io.find_one({
"type": "version",
"_id": representation["parent"]
})
# get corresponding node
GN = nuke.toNode(container['objectName'])

file = api.get_representation_path(representation).replace("\\", "/")
name = container['name']
version_data = version.get("data", {})
vname = version.get("name", None)
first = version_data.get("frameStart", None)
last = version_data.get("frameEnd", None)
namespace = container['namespace']
colorspace = version_data.get("colorspace", None)
object_name = "{}_{}".format(name, namespace)

add_keys = ["frameStart", "frameEnd", "handleStart", "handleEnd",
"source", "author", "fps"]

data_imprint = {"representation": str(representation["_id"]),
"frameStart": first,
"frameEnd": last,
"version": vname,
"colorspaceInput": colorspace,
"objectName": object_name}

for k in add_keys:
data_imprint.update({k: version_data[k]})

# adding nodes to node graph
# just in case we are in group lets jump out of it
nuke.endGroup()

with anlib.maintained_selection():
xpos = GN.xpos()
ypos = GN.ypos()
avalon_data = anlib.get_avalon_knob_data(GN)
nuke.delete(GN)
# add group from nk
nuke.nodePaste(file)

GN = nuke.selectedNode()
anlib.set_avalon_knob_data(GN, avalon_data)
GN.setXYpos(xpos, ypos)
GN["name"].setValue(object_name)

# get all versions in list
versions = io.find({
"type": "version",
"parent": version["parent"]
}).distinct('name')

max_version = max(versions)

# change color of node
if version.get("name") not in [max_version]:
GN["tile_color"].setValue(int("0xd88467ff", 16))
else:
GN["tile_color"].setValue(int(self.node_color, 16))

self.log.info("udated to version: {}".format(version.get("name")))

return update_container(GN, data_imprint)

def switch(self, container, representation):
self.update(container, representation)

def remove(self, container):
from avalon.nuke import viewer_update_and_undo_stop
node = nuke.toNode(container['objectName'])
with viewer_update_and_undo_stop():
nuke.delete(node)
1 change: 0 additions & 1 deletion pype/plugins/nuke/load/load_gizmo_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def update(self, container, representation):
GN = nuke.toNode(container['objectName'])

file = api.get_representation_path(representation).replace("\\", "/")
context = representation["context"]
name = container['name']
version_data = version.get("data", {})
vname = version.get("name", None)
Expand Down
2 changes: 1 addition & 1 deletion pype/plugins/nuke/publish/collect_gizmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def process(self, instance):

# get version
version = pype.get_version_from_path(nuke.root().name())
instance.data['version'] = version
instance.data['version'] = int(version)

# Add version data to instance
version_data = {
Expand Down
6 changes: 1 addition & 5 deletions pype/plugins/nuke/publish/collect_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def process(self, context):
except Exception as E:
self.log.warning(E)


# get data from avalon knob
self.log.debug("node[name]: {}".format(node['name'].value()))
avalon_knob_data = get_avalon_knob_data(node, ["avalon:", "ak:"])
Expand All @@ -60,7 +59,6 @@ def process(self, context):

families.append(family)


# except disabled nodes but exclude backdrops in test
if ("nukenodes" not in family) and (node["disable"].value()):
continue
Expand All @@ -75,8 +73,7 @@ def process(self, context):
# Add all nodes in group instances.
if node.Class() == "Group":
# only alter families for render family
if "write" in families_ak:

if "write" == families_ak:
if node["render"].value():
self.log.info("flagged for render")
add_family = "{}.local".format("render")
Expand All @@ -97,7 +94,6 @@ def process(self, context):

self.log.debug("__ families: `{}`".format(families))


# Get format
format = root['format'].value()
resolution_width = format.width()
Expand Down