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

Nuke: fixing node name based on switched asset name #2369

Merged
Merged
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
58 changes: 33 additions & 25 deletions openpype/hosts/nuke/plugins/load/load_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,7 @@ def load(self, context, name, namespace, options):
"Representation id `{}` is failing to load".format(repr_id))
return

name_data = {
"asset": repr_cont["asset"],
"subset": repr_cont["subset"],
"representation": context["representation"]["name"],
"ext": repr_cont["representation"],
"id": context["representation"]["_id"],
"class_name": self.__class__.__name__
}

read_name = self.node_name_template.format(**name_data)
read_name = self._get_node_name(context["representation"])

# Create the Loader with the filename path set
read_node = nuke.createNode(
Expand All @@ -143,7 +134,7 @@ def load(self, context, name, namespace, options):
elif iio_colorspace is not None:
read_node["colorspace"].setValue(iio_colorspace)

self.set_range_to_node(read_node, first, last, start_at_workfile)
self._set_range_to_node(read_node, first, last, start_at_workfile)

# add additional metadata from the version to imprint Avalon knob
add_keys = ["frameStart", "frameEnd",
Expand Down Expand Up @@ -171,7 +162,7 @@ def load(self, context, name, namespace, options):
data=data_imprint)

if version_data.get("retime", None):
self.make_retimes(read_node, version_data)
self._make_retimes(read_node, version_data)

self.set_as_member(read_node)

Expand Down Expand Up @@ -230,6 +221,9 @@ def update(self, container, representation):
"Representation id `{}` is failing to load".format(repr_id))
return

read_name = self._get_node_name(representation)

read_node["name"].setValue(read_name)
read_node["file"].setValue(file)

# to avoid multiple undo steps for rest of process
Expand All @@ -242,7 +236,7 @@ def update(self, container, representation):
elif iio_colorspace is not None:
read_node["colorspace"].setValue(iio_colorspace)

self.set_range_to_node(read_node, first, last, start_at_workfile)
self._set_range_to_node(read_node, first, last, start_at_workfile)

updated_dict = {
"representation": str(representation["_id"]),
Expand Down Expand Up @@ -279,21 +273,12 @@ def update(self, container, representation):
self.log.info("udated to version: {}".format(version.get("name")))

if version_data.get("retime", None):
self.make_retimes(read_node, version_data)
self._make_retimes(read_node, version_data)
else:
self.clear_members(read_node)

self.set_as_member(read_node)

def set_range_to_node(self, read_node, first, last, start_at_workfile):
read_node['origfirst'].setValue(int(first))
read_node['first'].setValue(int(first))
read_node['origlast'].setValue(int(last))
read_node['last'].setValue(int(last))

# set start frame depending on workfile or version
self.loader_shift(read_node, start_at_workfile)

def remove(self, container):

from avalon.nuke import viewer_update_and_undo_stop
Expand All @@ -307,7 +292,16 @@ def remove(self, container):
for member in members:
nuke.delete(member)

def make_retimes(self, parent_node, version_data):
def _set_range_to_node(self, read_node, first, last, start_at_workfile):
read_node['origfirst'].setValue(int(first))
read_node['first'].setValue(int(first))
read_node['origlast'].setValue(int(last))
read_node['last'].setValue(int(last))

# set start frame depending on workfile or version
self._loader_shift(read_node, start_at_workfile)

def _make_retimes(self, parent_node, version_data):
''' Create all retime and timewarping nodes with coppied animation '''
speed = version_data.get('speed', 1)
time_warp_nodes = version_data.get('timewarps', [])
Expand Down Expand Up @@ -360,7 +354,7 @@ def make_retimes(self, parent_node, version_data):
for i, n in enumerate(dependent_nodes):
last_node.setInput(i, n)

def loader_shift(self, read_node, workfile_start=False):
def _loader_shift(self, read_node, workfile_start=False):
""" Set start frame of read node to a workfile start

Args:
Expand All @@ -371,3 +365,17 @@ def loader_shift(self, read_node, workfile_start=False):
if workfile_start:
read_node['frame_mode'].setValue("start at")
read_node['frame'].setValue(str(self.script_start))

def _get_node_name(self, representation):

repr_cont = representation["context"]
name_data = {
"asset": repr_cont["asset"],
"subset": repr_cont["subset"],
"representation": representation["name"],
"ext": repr_cont["representation"],
"id": representation["_id"],
"class_name": self.__class__.__name__
}

return self.node_name_template.format(**name_data)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end of file