From 1707a783005ad09d87d049cb0c259540b946c58b Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 3 Dec 2021 15:07:57 +0100 Subject: [PATCH] Nuke: fixing node name based on switched asset name - also improving code --- openpype/hosts/nuke/plugins/load/load_clip.py | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_clip.py b/openpype/hosts/nuke/plugins/load/load_clip.py index 4ad2246e21b..9ce72c05196 100644 --- a/openpype/hosts/nuke/plugins/load/load_clip.py +++ b/openpype/hosts/nuke/plugins/load/load_clip.py @@ -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( @@ -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", @@ -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) @@ -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 @@ -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"]), @@ -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 @@ -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', []) @@ -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: @@ -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) \ No newline at end of file