From 1a75a6a041d83a2619b280af10b8c172338c9687 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 9 Dec 2022 16:19:28 +0100 Subject: [PATCH 1/6] flame: settings for layer renaming --- .../settings/defaults/project_settings/flame.json | 6 +++++- .../schemas/projects_schema/schema_project_flame.json | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/openpype/settings/defaults/project_settings/flame.json b/openpype/settings/defaults/project_settings/flame.json index 34baf9ba06..9966fdbd33 100644 --- a/openpype/settings/defaults/project_settings/flame.json +++ b/openpype/settings/defaults/project_settings/flame.json @@ -142,7 +142,11 @@ "exr16fpdwaa" ], "reel_name": "OP_LoadedReel", - "clip_name_template": "{batch}_{asset}_{subset}<_{output}>" + "clip_name_template": "{batch}_{asset}_{subset}<_{output}>", + "layer_rename_template": "{asset}_{subset}<_{output}>", + "layer_rename_patterns": [ + "rgba" + ] } } } \ No newline at end of file diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json b/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json index 73664300aa..26a2dce2f5 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json @@ -554,6 +554,17 @@ "type": "text", "key": "clip_name_template", "label": "Clip name template" + }, + { + "type": "text", + "key": "layer_rename_template", + "label": "Layer name template" + }, + { + "type": "list", + "key": "layer_rename_patterns", + "label": "Layer rename patters", + "object_type": "text" } ] } From 42764559330b63c91f6b3e1678bd9f79f0aa88fb Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 9 Dec 2022 16:20:08 +0100 Subject: [PATCH 2/6] flame: added layer renaming to batch loader --- openpype/hosts/flame/api/plugin.py | 56 +++++++++++++++++-- .../flame/plugins/load/load_clip_batch.py | 11 ++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/flame/api/plugin.py b/openpype/hosts/flame/api/plugin.py index ca113fd98a..6aaf0c6d80 100644 --- a/openpype/hosts/flame/api/plugin.py +++ b/openpype/hosts/flame/api/plugin.py @@ -8,7 +8,7 @@ import qargparse from Qt import QtCore, QtWidgets from openpype import style -from openpype.lib import Logger +from openpype.lib import Logger, StringTemplate from openpype.pipeline import LegacyCreator, LoaderPlugin from openpype.settings import get_current_project_settings @@ -775,6 +775,11 @@ class OpenClipSolver(flib.MediaInfoFile): self.feed_colorspace = feed_data.get("colorspace") self.log.debug("feed_version_name: {}".format(self.feed_version_name)) + # layer rename variables + self.layer_rename_template = feed_data["layer_rename_template"] + self.layer_rename_patterns = feed_data["layer_rename_patterns"] + self.context_data = feed_data["context_data"] + # derivate other feed variables self.feed_basename = os.path.basename(feed_path) self.feed_dir = os.path.dirname(feed_path) @@ -813,9 +818,11 @@ class OpenClipSolver(flib.MediaInfoFile): def _create_new_open_clip(self): self.log.info("Building new openClip") - self.log.debug(">> self.clip_data: {}".format(self.clip_data)) for tmp_xml_track in self.clip_data.iter("track"): + # solve track (layer) name + self._rename_track_name(tmp_xml_track) + tmp_xml_feeds = tmp_xml_track.find('feeds') tmp_xml_feeds.set('currentVersion', self.feed_version_name) @@ -850,6 +857,46 @@ class OpenClipSolver(flib.MediaInfoFile): if uid == track_uid: return xml_track + def _rename_track_name(self, xml_track_data): + name_obj = xml_track_data.find("name") + layer_name = name_obj.text + + if ( + self.layer_rename_patterns + and not any( + re.search(lp_.lower(), layer_name.lower()) + for lp_ in self.layer_rename_patterns + ) + ): + return + + formating_data = self._update_formating_data( + layer=layer_name + ) + name_obj.text = StringTemplate( + self.layer_rename_template + ).format(formating_data) + + def _update_formating_data(self, **kwargs): + """ Updating formating data for layer rename + + Attributes: + key=value (optional): will be included to formating data + as {key: value} + Returns: + dict: anatomy context data for formating + """ + self.log.debug(">> self.clip_data: {}".format(self.clip_data)) + clip_name_obj = self.clip_data.find("name") + data = { + "originalBasename": clip_name_obj.text + } + # include version context data + data.update(self.context_data) + # include input kwargs data + data.update(kwargs) + return data + def _update_open_clip(self): self.log.info("Updating openClip ..") @@ -857,11 +904,12 @@ class OpenClipSolver(flib.MediaInfoFile): out_xml = out_xml.getroot() self.log.debug(">> out_xml: {}".format(out_xml)) - self.log.debug(">> self.clip_data: {}".format(self.clip_data)) - # loop tmp tracks updated_any = False for tmp_xml_track in self.clip_data.iter("track"): + # solve track (layer) name + self._rename_track_name(tmp_xml_track) + # get tmp track uid tmp_track_uid = tmp_xml_track.get("uid") self.log.debug(">> tmp_track_uid: {}".format(tmp_track_uid)) diff --git a/openpype/hosts/flame/plugins/load/load_clip_batch.py b/openpype/hosts/flame/plugins/load/load_clip_batch.py index 048ac19431..96db04f6e3 100644 --- a/openpype/hosts/flame/plugins/load/load_clip_batch.py +++ b/openpype/hosts/flame/plugins/load/load_clip_batch.py @@ -25,6 +25,13 @@ class LoadClipBatch(opfapi.ClipLoader): reel_name = "OP_LoadedReel" clip_name_template = "{batch}_{asset}_{subset}<_{output}>" + """ Anatomy keys from version context data and dynamically added: + - {layer} - original layer name token + - {originalBasename} - original clip name taken from file + """ + layer_rename_template = "{asset}_{subset}<_{output}>" + layer_rename_patterns = [] + def load(self, context, name, namespace, options): # get flame objects @@ -40,6 +47,7 @@ class LoadClipBatch(opfapi.ClipLoader): # in case output is not in context replace key to representation if not context["representation"]["context"].get("output"): self.clip_name_template.replace("output", "representation") + self.layer_rename_template.replace("output", "representation") formating_data = deepcopy(context["representation"]["context"]) formating_data["batch"] = self.batch.name.get_value() @@ -69,6 +77,9 @@ class LoadClipBatch(opfapi.ClipLoader): "path": self.fname.replace("\\", "/"), "colorspace": colorspace, "version": "v{:0>3}".format(version_name), + "layer_rename_template": self.layer_rename_template, + "layer_rename_patterns": self.layer_rename_patterns, + "context_data": formating_data } self.log.debug(pformat( loading_context From 99e1c91a7531b0085f34192b50ef179afe22c76b Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 9 Dec 2022 16:57:12 +0100 Subject: [PATCH 3/6] flame: enhancing formatting data --- openpype/hosts/flame/api/plugin.py | 4 +++- openpype/hosts/flame/plugins/load/load_clip_batch.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/flame/api/plugin.py b/openpype/hosts/flame/api/plugin.py index 6aaf0c6d80..c682d294c5 100644 --- a/openpype/hosts/flame/api/plugin.py +++ b/openpype/hosts/flame/api/plugin.py @@ -858,6 +858,7 @@ class OpenClipSolver(flib.MediaInfoFile): return xml_track def _rename_track_name(self, xml_track_data): + layer_uid = xml_track_data.get("uid") name_obj = xml_track_data.find("name") layer_name = name_obj.text @@ -871,7 +872,8 @@ class OpenClipSolver(flib.MediaInfoFile): return formating_data = self._update_formating_data( - layer=layer_name + layerName=layer_name, + layerUID=layer_uid ) name_obj.text = StringTemplate( self.layer_rename_template diff --git a/openpype/hosts/flame/plugins/load/load_clip_batch.py b/openpype/hosts/flame/plugins/load/load_clip_batch.py index 96db04f6e3..47d7da2a76 100644 --- a/openpype/hosts/flame/plugins/load/load_clip_batch.py +++ b/openpype/hosts/flame/plugins/load/load_clip_batch.py @@ -26,7 +26,8 @@ class LoadClipBatch(opfapi.ClipLoader): clip_name_template = "{batch}_{asset}_{subset}<_{output}>" """ Anatomy keys from version context data and dynamically added: - - {layer} - original layer name token + - {layerName} - original layer name token + - {layerUID} - original layer UID token - {originalBasename} - original clip name taken from file """ layer_rename_template = "{asset}_{subset}<_{output}>" From 7d2229df4ab5164c98a1b811a06eae818bd04243 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 13 Dec 2022 15:30:59 +0100 Subject: [PATCH 4/6] flame: replicating multilayer rename to reel clip loader --- .../hosts/flame/plugins/load/load_clip.py | 20 ++++++++++++++++++- .../defaults/project_settings/flame.json | 6 +++++- .../projects_schema/schema_project_flame.json | 11 ++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/flame/plugins/load/load_clip.py b/openpype/hosts/flame/plugins/load/load_clip.py index f8cb7b3e11..2c107de2b4 100644 --- a/openpype/hosts/flame/plugins/load/load_clip.py +++ b/openpype/hosts/flame/plugins/load/load_clip.py @@ -1,3 +1,4 @@ +from copy import deepcopy import os import flame from pprint import pformat @@ -25,6 +26,14 @@ class LoadClip(opfapi.ClipLoader): reel_name = "Loaded" clip_name_template = "{asset}_{subset}<_{output}>" + """ Anatomy keys from version context data and dynamically added: + - {layerName} - original layer name token + - {layerUID} - original layer UID token + - {originalBasename} - original clip name taken from file + """ + layer_rename_template = "{asset}_{subset}<_{output}>" + layer_rename_patterns = [] + def load(self, context, name, namespace, options): # get flame objects @@ -38,8 +47,14 @@ class LoadClip(opfapi.ClipLoader): version_name = version.get("name", None) colorspace = self.get_colorspace(context) + # in case output is not in context replace key to representation + if not context["representation"]["context"].get("output"): + self.clip_name_template.replace("output", "representation") + self.layer_rename_template.replace("output", "representation") + + formating_data = deepcopy(context["representation"]["context"]) clip_name = StringTemplate(self.clip_name_template).format( - context["representation"]["context"]) + formating_data) # convert colorspace with ocio to flame mapping # in imageio flame section @@ -62,6 +77,9 @@ class LoadClip(opfapi.ClipLoader): "path": self.fname.replace("\\", "/"), "colorspace": colorspace, "version": "v{:0>3}".format(version_name), + "layer_rename_template": self.layer_rename_template, + "layer_rename_patterns": self.layer_rename_patterns, + "context_data": formating_data } self.log.debug(pformat( loading_context diff --git a/openpype/settings/defaults/project_settings/flame.json b/openpype/settings/defaults/project_settings/flame.json index 9966fdbd33..337e58ac62 100644 --- a/openpype/settings/defaults/project_settings/flame.json +++ b/openpype/settings/defaults/project_settings/flame.json @@ -119,7 +119,11 @@ ], "reel_group_name": "OpenPype_Reels", "reel_name": "Loaded", - "clip_name_template": "{asset}_{subset}<_{output}>" + "clip_name_template": "{asset}_{subset}<_{output}>", + "layer_rename_template": "{asset}_{subset}<_{output}>", + "layer_rename_patterns": [ + "rgba" + ] }, "LoadClipBatch": { "enabled": true, diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json b/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json index 26a2dce2f5..24726f2d07 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_flame.json @@ -512,6 +512,17 @@ "type": "text", "key": "clip_name_template", "label": "Clip name template" + }, + { + "type": "text", + "key": "layer_rename_template", + "label": "Layer name template" + }, + { + "type": "list", + "key": "layer_rename_patterns", + "label": "Layer rename patters", + "object_type": "text" } ] }, From a97f92760086eb34b1d07b4e68b6d850355d49eb Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 13 Dec 2022 21:35:01 +0100 Subject: [PATCH 5/6] fixing logic --- openpype/hosts/flame/plugins/load/load_clip.py | 6 ++++-- openpype/hosts/flame/plugins/load/load_clip_batch.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/flame/plugins/load/load_clip.py b/openpype/hosts/flame/plugins/load/load_clip.py index 2c107de2b4..6f47c23d57 100644 --- a/openpype/hosts/flame/plugins/load/load_clip.py +++ b/openpype/hosts/flame/plugins/load/load_clip.py @@ -49,8 +49,10 @@ class LoadClip(opfapi.ClipLoader): # in case output is not in context replace key to representation if not context["representation"]["context"].get("output"): - self.clip_name_template.replace("output", "representation") - self.layer_rename_template.replace("output", "representation") + self.clip_name_template = self.clip_name_template.replace( + "output", "representation") + self.layer_rename_template = self.layer_rename_template.replace( + "output", "representation") formating_data = deepcopy(context["representation"]["context"]) clip_name = StringTemplate(self.clip_name_template).format( diff --git a/openpype/hosts/flame/plugins/load/load_clip_batch.py b/openpype/hosts/flame/plugins/load/load_clip_batch.py index 47d7da2a76..5975c6e42f 100644 --- a/openpype/hosts/flame/plugins/load/load_clip_batch.py +++ b/openpype/hosts/flame/plugins/load/load_clip_batch.py @@ -47,8 +47,10 @@ class LoadClipBatch(opfapi.ClipLoader): # in case output is not in context replace key to representation if not context["representation"]["context"].get("output"): - self.clip_name_template.replace("output", "representation") - self.layer_rename_template.replace("output", "representation") + self.clip_name_template = self.clip_name_template.replace( + "output", "representation") + self.layer_rename_template = self.layer_rename_template.replace( + "output", "representation") formating_data = deepcopy(context["representation"]["context"]) formating_data["batch"] = self.batch.name.get_value() From 8ceafdbc367130e2bfb26e44f7f68e4d5a84acf1 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 16 Dec 2022 15:42:48 +0100 Subject: [PATCH 6/6] flame: adding also `rgb` layer to default rename --- openpype/settings/defaults/project_settings/flame.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openpype/settings/defaults/project_settings/flame.json b/openpype/settings/defaults/project_settings/flame.json index 337e58ac62..1422a76af3 100644 --- a/openpype/settings/defaults/project_settings/flame.json +++ b/openpype/settings/defaults/project_settings/flame.json @@ -122,6 +122,7 @@ "clip_name_template": "{asset}_{subset}<_{output}>", "layer_rename_template": "{asset}_{subset}<_{output}>", "layer_rename_patterns": [ + "rgb", "rgba" ] }, @@ -149,6 +150,7 @@ "clip_name_template": "{batch}_{asset}_{subset}<_{output}>", "layer_rename_template": "{asset}_{subset}<_{output}>", "layer_rename_patterns": [ + "rgb", "rgba" ] }