From f58994d59c970878c8d81cb1a1ec19b6748c482a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 17 Mar 2023 17:25:19 +0100 Subject: [PATCH] Loader: Remove `context` argument from Loader.__init__() (#4602) * Remove Loader `context` argument to __init__ * Add backwards compatibility for Loader.load by still setting `.fname` attr * Refactor/remove usage of `self.fname` in loaders * Fix some refactoring * Fix some refactoring * Hound * Revert invalid refactor * Fix refactor * Fix playblast panel collection * Refactor missing method * Fix typo * Use the correct `context` --------- Co-authored-by: Toke Stuart Jepsen Co-authored-by: Kayla Man <64118225+moonyuet@users.noreply.github.com> Co-authored-by: Jakub Trllo --- .../plugins/load/load_background.py | 5 ++-- .../aftereffects/plugins/load/load_file.py | 16 ++++++------- openpype/hosts/blender/api/plugin.py | 3 ++- .../blender/plugins/load/import_workfile.py | 6 +++-- .../hosts/blender/plugins/load/load_abc.py | 2 +- .../hosts/blender/plugins/load/load_action.py | 2 +- .../blender/plugins/load/load_animation.py | 2 +- .../hosts/blender/plugins/load/load_audio.py | 2 +- .../blender/plugins/load/load_camera_blend.py | 2 +- .../blender/plugins/load/load_camera_fbx.py | 2 +- .../hosts/blender/plugins/load/load_fbx.py | 2 +- .../blender/plugins/load/load_layout_blend.py | 2 +- .../blender/plugins/load/load_layout_json.py | 2 +- .../hosts/blender/plugins/load/load_look.py | 2 +- .../hosts/blender/plugins/load/load_model.py | 2 +- .../hosts/blender/plugins/load/load_rig.py | 2 +- .../hosts/flame/plugins/load/load_clip.py | 3 ++- .../flame/plugins/load/load_clip_batch.py | 5 ++-- .../hosts/fusion/plugins/load/load_alembic.py | 2 +- .../hosts/fusion/plugins/load/load_fbx.py | 2 +- .../fusion/plugins/load/load_sequence.py | 9 +++----- .../harmony/plugins/load/load_background.py | 5 ++-- .../plugins/load/load_imagesequence.py | 2 +- openpype/hosts/hiero/api/plugin.py | 6 +++-- .../hosts/hiero/plugins/load/load_clip.py | 3 ++- .../hosts/hiero/plugins/load/load_effects.py | 3 ++- .../houdini/plugins/load/load_alembic.py | 3 ++- .../plugins/load/load_alembic_archive.py | 3 ++- .../hosts/houdini/plugins/load/load_bgeo.py | 3 ++- .../hosts/houdini/plugins/load/load_camera.py | 3 ++- .../hosts/houdini/plugins/load/load_hda.py | 3 ++- .../hosts/houdini/plugins/load/load_image.py | 3 ++- .../houdini/plugins/load/load_usd_layer.py | 3 ++- .../plugins/load/load_usd_reference.py | 3 ++- .../hosts/houdini/plugins/load/load_vdb.py | 3 ++- .../houdini/plugins/load/show_usdview.py | 3 ++- .../hosts/max/plugins/load/load_camera_fbx.py | 3 ++- .../hosts/max/plugins/load/load_max_scene.py | 4 +++- .../hosts/max/plugins/load/load_pointcache.py | 3 ++- openpype/hosts/maya/api/plugin.py | 3 ++- .../maya/plugins/load/_load_animation.py | 3 ++- openpype/hosts/maya/plugins/load/actions.py | 3 ++- .../maya/plugins/load/load_arnold_standin.py | 5 ++-- .../hosts/maya/plugins/load/load_assembly.py | 2 +- .../hosts/maya/plugins/load/load_gpucache.py | 3 ++- openpype/hosts/maya/plugins/load/load_look.py | 6 +++-- .../hosts/maya/plugins/load/load_matchmove.py | 10 ++++---- .../maya/plugins/load/load_multiverse_usd.py | 4 +++- .../plugins/load/load_multiverse_usd_over.py | 3 ++- .../maya/plugins/load/load_redshift_proxy.py | 4 ++-- .../hosts/maya/plugins/load/load_reference.py | 3 ++- .../maya/plugins/load/load_rendersetup.py | 5 ++-- .../maya/plugins/load/load_vdb_to_arnold.py | 3 ++- .../maya/plugins/load/load_vdb_to_redshift.py | 2 +- .../maya/plugins/load/load_vdb_to_vray.py | 7 +++--- .../hosts/maya/plugins/load/load_vrayproxy.py | 8 ++++--- .../hosts/maya/plugins/load/load_vrayscene.py | 6 +++-- openpype/hosts/maya/plugins/load/load_xgen.py | 3 ++- .../maya/plugins/load/load_yeti_cache.py | 3 ++- .../hosts/maya/plugins/load/load_yeti_rig.py | 3 ++- .../hosts/nuke/plugins/load/load_backdrop.py | 2 +- .../nuke/plugins/load/load_camera_abc.py | 2 +- openpype/hosts/nuke/plugins/load/load_clip.py | 12 +++++----- .../hosts/nuke/plugins/load/load_effects.py | 2 +- .../nuke/plugins/load/load_effects_ip.py | 2 +- .../hosts/nuke/plugins/load/load_gizmo.py | 2 +- .../hosts/nuke/plugins/load/load_gizmo_ip.py | 2 +- .../hosts/nuke/plugins/load/load_image.py | 2 +- .../hosts/nuke/plugins/load/load_matchmove.py | 5 ++-- .../hosts/nuke/plugins/load/load_model.py | 2 +- .../nuke/plugins/load/load_script_precomp.py | 4 ++-- openpype/hosts/photoshop/api/README.md | 3 ++- .../photoshop/plugins/load/load_image.py | 3 ++- .../plugins/load/load_image_from_sequence.py | 10 ++++---- .../photoshop/plugins/load/load_reference.py | 3 ++- openpype/hosts/resolve/api/plugin.py | 3 ++- .../hosts/resolve/plugins/load/load_clip.py | 7 +++--- .../hosts/tvpaint/plugins/load/load_image.py | 3 ++- .../plugins/load/load_reference_image.py | 7 +++--- .../hosts/tvpaint/plugins/load/load_sound.py | 3 ++- .../tvpaint/plugins/load/load_workfile.py | 20 ++++++++-------- .../plugins/load/load_alembic_animation.py | 3 ++- .../unreal/plugins/load/load_animation.py | 9 ++++---- .../hosts/unreal/plugins/load/load_camera.py | 3 ++- .../plugins/load/load_geometrycache_abc.py | 3 ++- .../hosts/unreal/plugins/load/load_layout.py | 3 ++- .../plugins/load/load_layout_existing.py | 3 ++- .../plugins/load/load_skeletalmesh_abc.py | 3 ++- .../plugins/load/load_skeletalmesh_fbx.py | 5 ++-- .../plugins/load/load_staticmesh_abc.py | 3 ++- .../plugins/load/load_staticmesh_fbx.py | 3 ++- .../hosts/unreal/plugins/load/load_uasset.py | 3 ++- openpype/pipeline/load/plugins.py | 6 ----- openpype/pipeline/load/utils.py | 23 ++++++++++--------- openpype/plugins/load/copy_file.py | 5 ++-- openpype/plugins/load/copy_file_path.py | 5 ++-- openpype/plugins/load/open_djv.py | 6 +++-- openpype/plugins/load/open_file.py | 2 +- website/docs/dev_colorspace.md | 2 +- 99 files changed, 237 insertions(+), 175 deletions(-) diff --git a/openpype/hosts/aftereffects/plugins/load/load_background.py b/openpype/hosts/aftereffects/plugins/load/load_background.py index e7c29fee5a..16f45074aa 100644 --- a/openpype/hosts/aftereffects/plugins/load/load_background.py +++ b/openpype/hosts/aftereffects/plugins/load/load_background.py @@ -33,9 +33,10 @@ class BackgroundLoader(api.AfterEffectsLoader): existing_items, "{}_{}".format(context["asset"]["name"], name)) - layers = get_background_layers(self.fname) + path = self.filepath_from_context(context) + layers = get_background_layers(path) if not layers: - raise ValueError("No layers found in {}".format(self.fname)) + raise ValueError("No layers found in {}".format(path)) comp = stub.import_background(None, stub.LOADED_ICON + comp_name, layers) diff --git a/openpype/hosts/aftereffects/plugins/load/load_file.py b/openpype/hosts/aftereffects/plugins/load/load_file.py index 33a86aa505..def7c927ab 100644 --- a/openpype/hosts/aftereffects/plugins/load/load_file.py +++ b/openpype/hosts/aftereffects/plugins/load/load_file.py @@ -29,32 +29,32 @@ class FileLoader(api.AfterEffectsLoader): import_options = {} - file = self.fname + path = self.filepath_from_context(context) repr_cont = context["representation"]["context"] - if "#" not in file: + if "#" not in path: frame = repr_cont.get("frame") if frame: padding = len(frame) - file = file.replace(frame, "#" * padding) + path = path.replace(frame, "#" * padding) import_options['sequence'] = True - if not file: + if not path: repr_id = context["representation"]["_id"] self.log.warning( "Representation id `{}` is failing to load".format(repr_id)) return - file = file.replace("\\", "/") - if '.psd' in file: + path = path.replace("\\", "/") + if '.psd' in path: import_options['ImportAsType'] = 'ImportAsType.COMP' - comp = stub.import_file(self.fname, stub.LOADED_ICON + comp_name, + comp = stub.import_file(path, stub.LOADED_ICON + comp_name, import_options) if not comp: self.log.warning( - "Representation id `{}` is failing to load".format(file)) + "Representation `{}` is failing to load".format(path)) self.log.warning("Check host app for alert error.") return diff --git a/openpype/hosts/blender/api/plugin.py b/openpype/hosts/blender/api/plugin.py index 1274795c6b..fb87d08cce 100644 --- a/openpype/hosts/blender/api/plugin.py +++ b/openpype/hosts/blender/api/plugin.py @@ -243,7 +243,8 @@ class AssetLoader(LoaderPlugin): """ # TODO (jasper): make it possible to add the asset several times by # just re-using the collection - assert Path(self.fname).exists(), f"{self.fname} doesn't exist." + filepath = self.filepath_from_context(context) + assert Path(filepath).exists(), f"{filepath} doesn't exist." asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/import_workfile.py b/openpype/hosts/blender/plugins/load/import_workfile.py index bbdf1c7ea0..4f5016d422 100644 --- a/openpype/hosts/blender/plugins/load/import_workfile.py +++ b/openpype/hosts/blender/plugins/load/import_workfile.py @@ -52,7 +52,8 @@ class AppendBlendLoader(plugin.AssetLoader): color = "#775555" def load(self, context, name=None, namespace=None, data=None): - append_workfile(context, self.fname, False) + path = self.filepath_from_context(context) + append_workfile(context, path, False) # We do not containerize imported content, it remains unmanaged return @@ -76,7 +77,8 @@ class ImportBlendLoader(plugin.AssetLoader): color = "#775555" def load(self, context, name=None, namespace=None, data=None): - append_workfile(context, self.fname, True) + path = self.filepath_from_context(context) + append_workfile(context, path, True) # We do not containerize imported content, it remains unmanaged return diff --git a/openpype/hosts/blender/plugins/load/load_abc.py b/openpype/hosts/blender/plugins/load/load_abc.py index c1d73eff02..292925c833 100644 --- a/openpype/hosts/blender/plugins/load/load_abc.py +++ b/openpype/hosts/blender/plugins/load/load_abc.py @@ -111,7 +111,7 @@ class CacheModelLoader(plugin.AssetLoader): options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_action.py b/openpype/hosts/blender/plugins/load/load_action.py index 3c8fe988f0..3447e67ebf 100644 --- a/openpype/hosts/blender/plugins/load/load_action.py +++ b/openpype/hosts/blender/plugins/load/load_action.py @@ -43,7 +43,7 @@ class BlendActionLoader(openpype.hosts.blender.api.plugin.AssetLoader): options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] lib_container = openpype.hosts.blender.api.plugin.asset_name(asset, subset) diff --git a/openpype/hosts/blender/plugins/load/load_animation.py b/openpype/hosts/blender/plugins/load/load_animation.py index 6b8d4abd04..3e7f808903 100644 --- a/openpype/hosts/blender/plugins/load/load_animation.py +++ b/openpype/hosts/blender/plugins/load/load_animation.py @@ -34,7 +34,7 @@ class BlendAnimationLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) with bpy.data.libraries.load( libpath, link=True, relative=False diff --git a/openpype/hosts/blender/plugins/load/load_audio.py b/openpype/hosts/blender/plugins/load/load_audio.py index 3f4fcc17de..ac8f363316 100644 --- a/openpype/hosts/blender/plugins/load/load_audio.py +++ b/openpype/hosts/blender/plugins/load/load_audio.py @@ -38,7 +38,7 @@ class AudioLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_camera_blend.py b/openpype/hosts/blender/plugins/load/load_camera_blend.py index f00027f0b4..bd4820bf78 100644 --- a/openpype/hosts/blender/plugins/load/load_camera_blend.py +++ b/openpype/hosts/blender/plugins/load/load_camera_blend.py @@ -110,7 +110,7 @@ class BlendCameraLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_camera_fbx.py b/openpype/hosts/blender/plugins/load/load_camera_fbx.py index 97f844e610..b9d05dda0a 100644 --- a/openpype/hosts/blender/plugins/load/load_camera_fbx.py +++ b/openpype/hosts/blender/plugins/load/load_camera_fbx.py @@ -86,7 +86,7 @@ class FbxCameraLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_fbx.py b/openpype/hosts/blender/plugins/load/load_fbx.py index ee2e7d175c..e129ea6754 100644 --- a/openpype/hosts/blender/plugins/load/load_fbx.py +++ b/openpype/hosts/blender/plugins/load/load_fbx.py @@ -130,7 +130,7 @@ class FbxModelLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_layout_blend.py b/openpype/hosts/blender/plugins/load/load_layout_blend.py index 7d2fd23444..03ccbce3d7 100644 --- a/openpype/hosts/blender/plugins/load/load_layout_blend.py +++ b/openpype/hosts/blender/plugins/load/load_layout_blend.py @@ -267,7 +267,7 @@ class BlendLayoutLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] representation = str(context["representation"]["_id"]) diff --git a/openpype/hosts/blender/plugins/load/load_layout_json.py b/openpype/hosts/blender/plugins/load/load_layout_json.py index eca098627e..81683b8de8 100644 --- a/openpype/hosts/blender/plugins/load/load_layout_json.py +++ b/openpype/hosts/blender/plugins/load/load_layout_json.py @@ -144,7 +144,7 @@ class JsonLayoutLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_look.py b/openpype/hosts/blender/plugins/load/load_look.py index 70d1b95f02..c121f55633 100644 --- a/openpype/hosts/blender/plugins/load/load_look.py +++ b/openpype/hosts/blender/plugins/load/load_look.py @@ -92,7 +92,7 @@ class BlendLookLoader(plugin.AssetLoader): options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_model.py b/openpype/hosts/blender/plugins/load/load_model.py index 0a5d98ffa0..3210a4e841 100644 --- a/openpype/hosts/blender/plugins/load/load_model.py +++ b/openpype/hosts/blender/plugins/load/load_model.py @@ -113,7 +113,7 @@ class BlendModelLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/blender/plugins/load/load_rig.py b/openpype/hosts/blender/plugins/load/load_rig.py index 1d23a70061..b9b5ad935f 100644 --- a/openpype/hosts/blender/plugins/load/load_rig.py +++ b/openpype/hosts/blender/plugins/load/load_rig.py @@ -181,7 +181,7 @@ class BlendRigLoader(plugin.AssetLoader): context: Full parenthood of representation to load options: Additional settings dictionary """ - libpath = self.fname + libpath = self.filepath_from_context(context) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/openpype/hosts/flame/plugins/load/load_clip.py b/openpype/hosts/flame/plugins/load/load_clip.py index dfb2d2b6f0..338833b449 100644 --- a/openpype/hosts/flame/plugins/load/load_clip.py +++ b/openpype/hosts/flame/plugins/load/load_clip.py @@ -82,8 +82,9 @@ class LoadClip(opfapi.ClipLoader): os.makedirs(openclip_dir) # prepare clip data from context ad send it to openClipLoader + path = self.filepath_from_context(context) loading_context = { - "path": self.fname.replace("\\", "/"), + "path": path.replace("\\", "/"), "colorspace": colorspace, "version": "v{:0>3}".format(version_name), "layer_rename_template": 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 5c5a77f0d0..ca43b94ee9 100644 --- a/openpype/hosts/flame/plugins/load/load_clip_batch.py +++ b/openpype/hosts/flame/plugins/load/load_clip_batch.py @@ -81,9 +81,10 @@ class LoadClipBatch(opfapi.ClipLoader): if not os.path.exists(openclip_dir): os.makedirs(openclip_dir) - # prepare clip data from context ad send it to openClipLoader + # prepare clip data from context and send it to openClipLoader + path = self.filepath_from_context(context) loading_context = { - "path": self.fname.replace("\\", "/"), + "path": path.replace("\\", "/"), "colorspace": colorspace, "version": "v{:0>3}".format(version_name), "layer_rename_template": self.layer_rename_template, diff --git a/openpype/hosts/fusion/plugins/load/load_alembic.py b/openpype/hosts/fusion/plugins/load/load_alembic.py index 11bf59af12..9b6d1e12b4 100644 --- a/openpype/hosts/fusion/plugins/load/load_alembic.py +++ b/openpype/hosts/fusion/plugins/load/load_alembic.py @@ -32,7 +32,7 @@ class FusionLoadAlembicMesh(load.LoaderPlugin): comp = get_current_comp() with comp_lock_and_undo_chunk(comp, "Create tool"): - path = self.fname + path = self.filepath_from_context(context) args = (-32768, -32768) tool = comp.AddTool(self.tool_type, *args) diff --git a/openpype/hosts/fusion/plugins/load/load_fbx.py b/openpype/hosts/fusion/plugins/load/load_fbx.py index c73ad78394..d15d2c33d7 100644 --- a/openpype/hosts/fusion/plugins/load/load_fbx.py +++ b/openpype/hosts/fusion/plugins/load/load_fbx.py @@ -45,7 +45,7 @@ class FusionLoadFBXMesh(load.LoaderPlugin): # Create the Loader with the filename path set comp = get_current_comp() with comp_lock_and_undo_chunk(comp, "Create tool"): - path = self.fname + path = self.filepath_from_context(context) args = (-32768, -32768) tool = comp.AddTool(self.tool_type, *args) diff --git a/openpype/hosts/fusion/plugins/load/load_sequence.py b/openpype/hosts/fusion/plugins/load/load_sequence.py index 552e282587..20be5faaba 100644 --- a/openpype/hosts/fusion/plugins/load/load_sequence.py +++ b/openpype/hosts/fusion/plugins/load/load_sequence.py @@ -1,10 +1,7 @@ import contextlib import openpype.pipeline.load as load -from openpype.pipeline.load import ( - get_representation_context, - get_representation_path_from_context, -) +from openpype.pipeline.load import get_representation_context from openpype.hosts.fusion.api import ( imprint_container, get_current_comp, @@ -157,7 +154,7 @@ class FusionLoadSequence(load.LoaderPlugin): namespace = context["asset"]["name"] # Use the first file for now - path = get_representation_path_from_context(context) + path = self.filepath_from_context(context) # Create the Loader with the filename path set comp = get_current_comp() @@ -228,7 +225,7 @@ class FusionLoadSequence(load.LoaderPlugin): comp = tool.Comp() context = get_representation_context(representation) - path = get_representation_path_from_context(context) + path = self.filepath_from_context(context) # Get start frame from version data start = self._get_start(context["version"], tool) diff --git a/openpype/hosts/harmony/plugins/load/load_background.py b/openpype/hosts/harmony/plugins/load/load_background.py index c28a87791e..853d347c2e 100644 --- a/openpype/hosts/harmony/plugins/load/load_background.py +++ b/openpype/hosts/harmony/plugins/load/load_background.py @@ -238,7 +238,8 @@ class BackgroundLoader(load.LoaderPlugin): def load(self, context, name=None, namespace=None, data=None): - with open(self.fname) as json_file: + path = self.filepath_from_context(context) + with open(path) as json_file: data = json.load(json_file) layers = list() @@ -251,7 +252,7 @@ class BackgroundLoader(load.LoaderPlugin): if layer.get("filename"): layers.append(layer["filename"]) - bg_folder = os.path.dirname(self.fname) + bg_folder = os.path.dirname(path) subset_name = context["subset"]["name"] # read_node_name += "_{}".format(uuid.uuid4()) diff --git a/openpype/hosts/harmony/plugins/load/load_imagesequence.py b/openpype/hosts/harmony/plugins/load/load_imagesequence.py index b95d25f507..754f82e5d5 100644 --- a/openpype/hosts/harmony/plugins/load/load_imagesequence.py +++ b/openpype/hosts/harmony/plugins/load/load_imagesequence.py @@ -34,7 +34,7 @@ class ImageSequenceLoader(load.LoaderPlugin): data (dict, optional): Additional data passed into loader. """ - fname = Path(self.fname) + fname = Path(self.filepath_from_context(context)) self_name = self.__class__.__name__ collections, remainder = clique.assemble( os.listdir(fname.parent.as_posix()) diff --git a/openpype/hosts/hiero/api/plugin.py b/openpype/hosts/hiero/api/plugin.py index a3f8a6c524..65a4009756 100644 --- a/openpype/hosts/hiero/api/plugin.py +++ b/openpype/hosts/hiero/api/plugin.py @@ -12,6 +12,7 @@ from openpype.settings import get_current_project_settings from openpype.lib import Logger from openpype.pipeline import LoaderPlugin, LegacyCreator from openpype.pipeline.context_tools import get_current_project_asset +from openpype.pipeline.load import get_representation_path_from_context from . import lib log = Logger.get_logger(__name__) @@ -393,7 +394,7 @@ class ClipLoader: active_bin = None data = dict() - def __init__(self, cls, context, **options): + def __init__(self, cls, context, path, **options): """ Initialize object Arguments: @@ -406,6 +407,7 @@ class ClipLoader: self.__dict__.update(cls.__dict__) self.context = context self.active_project = lib.get_current_project() + self.fname = path # try to get value from options or evaluate key value for `handles` self.with_handles = options.get("handles") or bool( @@ -467,7 +469,7 @@ class ClipLoader: self.data["track_name"] = "_".join([subset, representation]) self.data["versionData"] = self.context["version"]["data"] # gets file path - file = self.fname + file = get_representation_path_from_context(self.context) if not file: repr_id = repr["_id"] log.warning( diff --git a/openpype/hosts/hiero/plugins/load/load_clip.py b/openpype/hosts/hiero/plugins/load/load_clip.py index c9bebfa8b2..71df52f0f8 100644 --- a/openpype/hosts/hiero/plugins/load/load_clip.py +++ b/openpype/hosts/hiero/plugins/load/load_clip.py @@ -87,7 +87,8 @@ class LoadClip(phiero.SequenceLoader): }) # load clip to timeline and get main variables - track_item = phiero.ClipLoader(self, context, **options).load() + path = self.filepath_from_context(context) + track_item = phiero.ClipLoader(self, context, path, **options).load() namespace = namespace or track_item.name() version = context['version'] version_data = version.get("data", {}) diff --git a/openpype/hosts/hiero/plugins/load/load_effects.py b/openpype/hosts/hiero/plugins/load/load_effects.py index b61cca9731..4b86149166 100644 --- a/openpype/hosts/hiero/plugins/load/load_effects.py +++ b/openpype/hosts/hiero/plugins/load/load_effects.py @@ -59,7 +59,8 @@ class LoadEffects(load.LoaderPlugin): } # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context) + file = file.replace("\\", "/") if self._shared_loading( file, diff --git a/openpype/hosts/houdini/plugins/load/load_alembic.py b/openpype/hosts/houdini/plugins/load/load_alembic.py index c6f0ebf2f9..48bd730ebe 100644 --- a/openpype/hosts/houdini/plugins/load/load_alembic.py +++ b/openpype/hosts/houdini/plugins/load/load_alembic.py @@ -20,7 +20,8 @@ class AbcLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_alembic_archive.py b/openpype/hosts/houdini/plugins/load/load_alembic_archive.py index 47d2e1b896..3a577f72b4 100644 --- a/openpype/hosts/houdini/plugins/load/load_alembic_archive.py +++ b/openpype/hosts/houdini/plugins/load/load_alembic_archive.py @@ -21,7 +21,8 @@ class AbcArchiveLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_bgeo.py b/openpype/hosts/houdini/plugins/load/load_bgeo.py index 86e8675c02..22680178c0 100644 --- a/openpype/hosts/houdini/plugins/load/load_bgeo.py +++ b/openpype/hosts/houdini/plugins/load/load_bgeo.py @@ -43,9 +43,10 @@ class BgeoLoader(load.LoaderPlugin): file_node.destroy() # Explicitly create a file node + path = self.filepath_from_context(context) file_node = container.createNode("file", node_name=node_name) file_node.setParms( - {"file": self.format_path(self.fname, context["representation"])}) + {"file": self.format_path(path, context["representation"])}) # Set display on last node file_node.setDisplayFlag(True) diff --git a/openpype/hosts/houdini/plugins/load/load_camera.py b/openpype/hosts/houdini/plugins/load/load_camera.py index 6365508f4e..7b4a04809e 100644 --- a/openpype/hosts/houdini/plugins/load/load_camera.py +++ b/openpype/hosts/houdini/plugins/load/load_camera.py @@ -94,7 +94,8 @@ class CameraLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_hda.py b/openpype/hosts/houdini/plugins/load/load_hda.py index 2438570c6e..57edc341a3 100644 --- a/openpype/hosts/houdini/plugins/load/load_hda.py +++ b/openpype/hosts/houdini/plugins/load/load_hda.py @@ -21,7 +21,8 @@ class HdaLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_image.py b/openpype/hosts/houdini/plugins/load/load_image.py index 26bc569c53..663a93e48b 100644 --- a/openpype/hosts/houdini/plugins/load/load_image.py +++ b/openpype/hosts/houdini/plugins/load/load_image.py @@ -55,7 +55,8 @@ class ImageLoader(load.LoaderPlugin): def load(self, context, name=None, namespace=None, data=None): # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") file_path = self._get_file_sequence(file_path) diff --git a/openpype/hosts/houdini/plugins/load/load_usd_layer.py b/openpype/hosts/houdini/plugins/load/load_usd_layer.py index 1f0ec25128..1528cf549f 100644 --- a/openpype/hosts/houdini/plugins/load/load_usd_layer.py +++ b/openpype/hosts/houdini/plugins/load/load_usd_layer.py @@ -26,7 +26,8 @@ class USDSublayerLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_usd_reference.py b/openpype/hosts/houdini/plugins/load/load_usd_reference.py index f66d05395e..8402ad072c 100644 --- a/openpype/hosts/houdini/plugins/load/load_usd_reference.py +++ b/openpype/hosts/houdini/plugins/load/load_usd_reference.py @@ -26,7 +26,8 @@ class USDReferenceLoader(load.LoaderPlugin): import hou # Format file name, Houdini only wants forward slashes - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) file_path = file_path.replace("\\", "/") # Get the root node diff --git a/openpype/hosts/houdini/plugins/load/load_vdb.py b/openpype/hosts/houdini/plugins/load/load_vdb.py index 87900502c5..bcc4f200d3 100644 --- a/openpype/hosts/houdini/plugins/load/load_vdb.py +++ b/openpype/hosts/houdini/plugins/load/load_vdb.py @@ -40,8 +40,9 @@ class VdbLoader(load.LoaderPlugin): # Explicitly create a file node file_node = container.createNode("file", node_name=node_name) + path = self.filepath_from_context(context) file_node.setParms( - {"file": self.format_path(self.fname, context["representation"])}) + {"file": self.format_path(path, context["representation"])}) # Set display on last node file_node.setDisplayFlag(True) diff --git a/openpype/hosts/houdini/plugins/load/show_usdview.py b/openpype/hosts/houdini/plugins/load/show_usdview.py index 2737bc40fa..7b03a0738a 100644 --- a/openpype/hosts/houdini/plugins/load/show_usdview.py +++ b/openpype/hosts/houdini/plugins/load/show_usdview.py @@ -20,7 +20,8 @@ class ShowInUsdview(load.LoaderPlugin): usdview = find_executable("usdview") - filepath = os.path.normpath(self.fname) + filepath = self.filepath_from_context(context) + filepath = os.path.normpath(filepath) filepath = filepath.replace("\\", "/") if not os.path.exists(filepath): diff --git a/openpype/hosts/max/plugins/load/load_camera_fbx.py b/openpype/hosts/max/plugins/load/load_camera_fbx.py index c51900dbb7..62284b23d9 100644 --- a/openpype/hosts/max/plugins/load/load_camera_fbx.py +++ b/openpype/hosts/max/plugins/load/load_camera_fbx.py @@ -17,7 +17,8 @@ class FbxLoader(load.LoaderPlugin): def load(self, context, name=None, namespace=None, data=None): from pymxs import runtime as rt - filepath = os.path.normpath(self.fname) + filepath = self.filepath_from_context(context) + filepath = os.path.normpath(filepath) rt.FBXImporterSetParam("Animation", True) rt.FBXImporterSetParam("Camera", True) rt.FBXImporterSetParam("AxisConversionMethod", True) diff --git a/openpype/hosts/max/plugins/load/load_max_scene.py b/openpype/hosts/max/plugins/load/load_max_scene.py index e3fb34f5bc..76cd3bf367 100644 --- a/openpype/hosts/max/plugins/load/load_max_scene.py +++ b/openpype/hosts/max/plugins/load/load_max_scene.py @@ -19,7 +19,9 @@ class MaxSceneLoader(load.LoaderPlugin): def load(self, context, name=None, namespace=None, data=None): from pymxs import runtime as rt - path = os.path.normpath(self.fname) + + path = self.filepath_from_context(context) + path = os.path.normpath(path) # import the max scene by using "merge file" path = path.replace('\\', '/') rt.MergeMaxFile(path) diff --git a/openpype/hosts/max/plugins/load/load_pointcache.py b/openpype/hosts/max/plugins/load/load_pointcache.py index cadbe7cac2..290503e053 100644 --- a/openpype/hosts/max/plugins/load/load_pointcache.py +++ b/openpype/hosts/max/plugins/load/load_pointcache.py @@ -23,7 +23,8 @@ class AbcLoader(load.LoaderPlugin): def load(self, context, name=None, namespace=None, data=None): from pymxs import runtime as rt - file_path = os.path.normpath(self.fname) + file_path = self.filepath_from_context(context) + file_path = os.path.normpath(file_path) abc_before = { c diff --git a/openpype/hosts/maya/api/plugin.py b/openpype/hosts/maya/api/plugin.py index 9a67147eb4..2b5aee9700 100644 --- a/openpype/hosts/maya/api/plugin.py +++ b/openpype/hosts/maya/api/plugin.py @@ -485,7 +485,8 @@ class ReferenceLoader(Loader): namespace=None, options=None ): - assert os.path.exists(self.fname), "%s does not exist." % self.fname + path = self.filepath_from_context(context) + assert os.path.exists(path), "%s does not exist." % path asset = context['asset'] subset = context['subset'] diff --git a/openpype/hosts/maya/plugins/load/_load_animation.py b/openpype/hosts/maya/plugins/load/_load_animation.py index 2ba5fe6b64..49792b2806 100644 --- a/openpype/hosts/maya/plugins/load/_load_animation.py +++ b/openpype/hosts/maya/plugins/load/_load_animation.py @@ -35,7 +35,8 @@ class AbcLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): # hero_001 (abc) # asset_counter{optional} - file_url = self.prepare_root_value(self.fname, + path = self.filepath_from_context(context) + file_url = self.prepare_root_value(path, context["project"]["name"]) nodes = cmds.file(file_url, namespace=namespace, diff --git a/openpype/hosts/maya/plugins/load/actions.py b/openpype/hosts/maya/plugins/load/actions.py index 4855f3eed0..348657e592 100644 --- a/openpype/hosts/maya/plugins/load/actions.py +++ b/openpype/hosts/maya/plugins/load/actions.py @@ -138,8 +138,9 @@ class ImportMayaLoader(load.LoaderPlugin): suffix="_", ) + path = self.filepath_from_context(context) with maintained_selection(): - nodes = cmds.file(self.fname, + nodes = cmds.file(path, i=True, preserveReferences=True, namespace=namespace, diff --git a/openpype/hosts/maya/plugins/load/load_arnold_standin.py b/openpype/hosts/maya/plugins/load/load_arnold_standin.py index 29215bc5c2..b5cc4d629b 100644 --- a/openpype/hosts/maya/plugins/load/load_arnold_standin.py +++ b/openpype/hosts/maya/plugins/load/load_arnold_standin.py @@ -89,11 +89,12 @@ class ArnoldStandinLoader(load.LoaderPlugin): cmds.parent(standin, root) # Set the standin filepath + repre_path = self.filepath_from_context(context) path, operator = self._setup_proxy( - standin_shape, self.fname, namespace + standin_shape, repre_path, namespace ) cmds.setAttr(standin_shape + ".dso", path, type="string") - sequence = is_sequence(os.listdir(os.path.dirname(self.fname))) + sequence = is_sequence(os.listdir(os.path.dirname(repre_path))) cmds.setAttr(standin_shape + ".useFrameExtension", sequence) fps = float(version["data"].get("fps"))or get_current_session_fps() diff --git a/openpype/hosts/maya/plugins/load/load_assembly.py b/openpype/hosts/maya/plugins/load/load_assembly.py index 275f21be5d..0a2733e03c 100644 --- a/openpype/hosts/maya/plugins/load/load_assembly.py +++ b/openpype/hosts/maya/plugins/load/load_assembly.py @@ -30,7 +30,7 @@ class AssemblyLoader(load.LoaderPlugin): ) containers = setdress.load_package( - filepath=self.fname, + filepath=self.filepath_from_context(context), name=name, namespace=namespace ) diff --git a/openpype/hosts/maya/plugins/load/load_gpucache.py b/openpype/hosts/maya/plugins/load/load_gpucache.py index 794b21eb5d..52be1ca645 100644 --- a/openpype/hosts/maya/plugins/load/load_gpucache.py +++ b/openpype/hosts/maya/plugins/load/load_gpucache.py @@ -56,7 +56,8 @@ class GpuCacheLoader(load.LoaderPlugin): name="{0}Shape".format(transform_name)) # Set the cache filepath - cmds.setAttr(cache + '.cacheFileName', self.fname, type="string") + path = self.filepath_from_context(context) + cmds.setAttr(cache + '.cacheFileName', path, type="string") cmds.setAttr(cache + '.cacheGeomPath', "|", type="string") # root # Lock parenting of the transform and cache diff --git a/openpype/hosts/maya/plugins/load/load_look.py b/openpype/hosts/maya/plugins/load/load_look.py index b060ae2b05..3cc87b7ef4 100644 --- a/openpype/hosts/maya/plugins/load/load_look.py +++ b/openpype/hosts/maya/plugins/load/load_look.py @@ -32,8 +32,10 @@ class LookLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): from maya import cmds with lib.maintained_selection(): - file_url = self.prepare_root_value(self.fname, - context["project"]["name"]) + file_url = self.prepare_root_value( + file_url=self.filepath_from_context(context), + project_name=context["project"]["name"] + ) nodes = cmds.file(file_url, namespace=namespace, reference=True, diff --git a/openpype/hosts/maya/plugins/load/load_matchmove.py b/openpype/hosts/maya/plugins/load/load_matchmove.py index ee3332bd09..46d1be8300 100644 --- a/openpype/hosts/maya/plugins/load/load_matchmove.py +++ b/openpype/hosts/maya/plugins/load/load_matchmove.py @@ -1,7 +1,6 @@ from maya import mel from openpype.pipeline import load - class MatchmoveLoader(load.LoaderPlugin): """ This will run matchmove script to create track in scene. @@ -18,11 +17,12 @@ class MatchmoveLoader(load.LoaderPlugin): color = "orange" def load(self, context, name, namespace, data): - if self.fname.lower().endswith(".py"): - exec(open(self.fname).read()) + path = self.filepath_from_context(context) + if path.lower().endswith(".py"): + exec(open(path).read()) - elif self.fname.lower().endswith(".mel"): - mel.eval('source "{}"'.format(self.fname)) + elif path.lower().endswith(".mel"): + mel.eval('source "{}"'.format(path)) else: self.log.error("Unsupported script type") diff --git a/openpype/hosts/maya/plugins/load/load_multiverse_usd.py b/openpype/hosts/maya/plugins/load/load_multiverse_usd.py index 9e0d38df46..d08fcd904e 100644 --- a/openpype/hosts/maya/plugins/load/load_multiverse_usd.py +++ b/openpype/hosts/maya/plugins/load/load_multiverse_usd.py @@ -36,6 +36,8 @@ class MultiverseUsdLoader(load.LoaderPlugin): suffix="_", ) + path = self.filepath_from_context(context) + # Make sure we can load the plugin cmds.loadPlugin("MultiverseForMaya", quiet=True) import multiverse @@ -46,7 +48,7 @@ class MultiverseUsdLoader(load.LoaderPlugin): with maintained_selection(): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): - shape = multiverse.CreateUsdCompound(self.fname) + shape = multiverse.CreateUsdCompound(path) transform = cmds.listRelatives( shape, parent=True, fullPath=True)[0] diff --git a/openpype/hosts/maya/plugins/load/load_multiverse_usd_over.py b/openpype/hosts/maya/plugins/load/load_multiverse_usd_over.py index 8a25508ac2..be8d78607b 100644 --- a/openpype/hosts/maya/plugins/load/load_multiverse_usd_over.py +++ b/openpype/hosts/maya/plugins/load/load_multiverse_usd_over.py @@ -50,9 +50,10 @@ class MultiverseUsdOverLoader(load.LoaderPlugin): cmds.loadPlugin("MultiverseForMaya", quiet=True) import multiverse + path = self.filepath_from_context(context) nodes = current_usd with maintained_selection(): - multiverse.AddUsdCompoundAssetPath(current_usd[0], self.fname) + multiverse.AddUsdCompoundAssetPath(current_usd[0], path) namespace = current_usd[0].split("|")[1].split(":")[0] diff --git a/openpype/hosts/maya/plugins/load/load_redshift_proxy.py b/openpype/hosts/maya/plugins/load/load_redshift_proxy.py index c288e23ded..a44482d21d 100644 --- a/openpype/hosts/maya/plugins/load/load_redshift_proxy.py +++ b/openpype/hosts/maya/plugins/load/load_redshift_proxy.py @@ -46,11 +46,11 @@ class RedshiftProxyLoader(load.LoaderPlugin): # Ensure Redshift for Maya is loaded. cmds.loadPlugin("redshift4maya", quiet=True) + path = self.filepath_from_context(context) with maintained_selection(): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): - nodes, group_node = self.create_rs_proxy( - name, self.fname) + nodes, group_node = self.create_rs_proxy(name, path) self[:] = nodes if not nodes: diff --git a/openpype/hosts/maya/plugins/load/load_reference.py b/openpype/hosts/maya/plugins/load/load_reference.py index deadd5b9d3..5c838fbc3c 100644 --- a/openpype/hosts/maya/plugins/load/load_reference.py +++ b/openpype/hosts/maya/plugins/load/load_reference.py @@ -122,9 +122,10 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): attach_to_root = options.get("attach_to_root", True) group_name = options["group_name"] + path = self.filepath_from_context(context) with maintained_selection(): cmds.loadPlugin("AbcImport.mll", quiet=True) - file_url = self.prepare_root_value(self.fname, + file_url = self.prepare_root_value(path, context["project"]["name"]) nodes = cmds.file(file_url, diff --git a/openpype/hosts/maya/plugins/load/load_rendersetup.py b/openpype/hosts/maya/plugins/load/load_rendersetup.py index 7a2d8b1002..8b85f11958 100644 --- a/openpype/hosts/maya/plugins/load/load_rendersetup.py +++ b/openpype/hosts/maya/plugins/load/load_rendersetup.py @@ -43,8 +43,9 @@ class RenderSetupLoader(load.LoaderPlugin): prefix="_" if asset[0].isdigit() else "", suffix="_", ) - self.log.info(">>> loading json [ {} ]".format(self.fname)) - with open(self.fname, "r") as file: + path = self.filepath_from_context(context) + self.log.info(">>> loading json [ {} ]".format(path)) + with open(path, "r") as file: renderSetup.instance().decode( json.load(file), renderSetup.DECODE_AND_OVERWRITE, None) diff --git a/openpype/hosts/maya/plugins/load/load_vdb_to_arnold.py b/openpype/hosts/maya/plugins/load/load_vdb_to_arnold.py index 8a386cecfd..13fd156216 100644 --- a/openpype/hosts/maya/plugins/load/load_vdb_to_arnold.py +++ b/openpype/hosts/maya/plugins/load/load_vdb_to_arnold.py @@ -65,8 +65,9 @@ class LoadVDBtoArnold(load.LoaderPlugin): name="{}Shape".format(root), parent=root) + path = self.filepath_from_context(context) self._set_path(grid_node, - path=self.fname, + path=path, representation=context["representation"]) # Lock the shape node so the user can't delete the transform/shape diff --git a/openpype/hosts/maya/plugins/load/load_vdb_to_redshift.py b/openpype/hosts/maya/plugins/load/load_vdb_to_redshift.py index 1f02321dc8..464d5b0ba8 100644 --- a/openpype/hosts/maya/plugins/load/load_vdb_to_redshift.py +++ b/openpype/hosts/maya/plugins/load/load_vdb_to_redshift.py @@ -85,7 +85,7 @@ class LoadVDBtoRedShift(load.LoaderPlugin): parent=root) self._set_path(volume_node, - path=self.fname, + path=self.filepath_from_context(context), representation=context["representation"]) nodes = [root, volume_node] diff --git a/openpype/hosts/maya/plugins/load/load_vdb_to_vray.py b/openpype/hosts/maya/plugins/load/load_vdb_to_vray.py index 9267c59c02..69eb44a5e9 100644 --- a/openpype/hosts/maya/plugins/load/load_vdb_to_vray.py +++ b/openpype/hosts/maya/plugins/load/load_vdb_to_vray.py @@ -88,8 +88,9 @@ class LoadVDBtoVRay(load.LoaderPlugin): from openpype.hosts.maya.api.lib import unique_namespace from openpype.hosts.maya.api.pipeline import containerise - assert os.path.exists(self.fname), ( - "Path does not exist: %s" % self.fname + path = self.filepath_from_context(context) + assert os.path.exists(path), ( + "Path does not exist: %s" % path ) try: @@ -146,7 +147,7 @@ class LoadVDBtoVRay(load.LoaderPlugin): cmds.connectAttr("time1.outTime", grid_node + ".currentTime") # Set path - self._set_path(grid_node, self.fname, show_preset_popup=True) + self._set_path(grid_node, path, show_preset_popup=True) # Lock the shape node so the user can't delete the transform/shape # as if it was referenced diff --git a/openpype/hosts/maya/plugins/load/load_vrayproxy.py b/openpype/hosts/maya/plugins/load/load_vrayproxy.py index 64184f9e7b..77efdb2069 100644 --- a/openpype/hosts/maya/plugins/load/load_vrayproxy.py +++ b/openpype/hosts/maya/plugins/load/load_vrayproxy.py @@ -53,7 +53,9 @@ class VRayProxyLoader(load.LoaderPlugin): family = "vrayproxy" # get all representations for this version - self.fname = self._get_abc(context["version"]["_id"]) or self.fname + filename = self._get_abc(context["version"]["_id"]) + if not filename: + filename = self.filepath_from_context(context) asset_name = context['asset']["name"] namespace = namespace or unique_namespace( @@ -69,7 +71,7 @@ class VRayProxyLoader(load.LoaderPlugin): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): nodes, group_node = self.create_vray_proxy( - name, filename=self.fname) + name, filename=filename) self[:] = nodes if not nodes: @@ -190,7 +192,7 @@ class VRayProxyLoader(load.LoaderPlugin): if abc_rep: self.log.debug("Found, we'll link alembic to vray proxy.") file_name = get_representation_path(abc_rep) - self.log.debug("File: {}".format(self.fname)) + self.log.debug("File: {}".format(file_name)) return file_name return "" diff --git a/openpype/hosts/maya/plugins/load/load_vrayscene.py b/openpype/hosts/maya/plugins/load/load_vrayscene.py index d87992f9a7..f9169ff884 100644 --- a/openpype/hosts/maya/plugins/load/load_vrayscene.py +++ b/openpype/hosts/maya/plugins/load/load_vrayscene.py @@ -46,8 +46,10 @@ class VRaySceneLoader(load.LoaderPlugin): with maintained_selection(): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): - nodes, root_node = self.create_vray_scene(name, - filename=self.fname) + nodes, root_node = self.create_vray_scene( + name, + filename=self.filepath_from_context(context) + ) self[:] = nodes if not nodes: diff --git a/openpype/hosts/maya/plugins/load/load_xgen.py b/openpype/hosts/maya/plugins/load/load_xgen.py index 16f2e8e842..323f8d7eda 100644 --- a/openpype/hosts/maya/plugins/load/load_xgen.py +++ b/openpype/hosts/maya/plugins/load/load_xgen.py @@ -48,7 +48,8 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): return maya_filepath = self.prepare_root_value( - self.fname, context["project"]["name"] + file_url=self.filepath_from_context(context), + project_name=context["project"]["name"] ) # Reference xgen. Xgen does not like being referenced in under a group. diff --git a/openpype/hosts/maya/plugins/load/load_yeti_cache.py b/openpype/hosts/maya/plugins/load/load_yeti_cache.py index 5ba381050a..833be79ef2 100644 --- a/openpype/hosts/maya/plugins/load/load_yeti_cache.py +++ b/openpype/hosts/maya/plugins/load/load_yeti_cache.py @@ -60,7 +60,8 @@ class YetiCacheLoader(load.LoaderPlugin): cmds.loadPlugin("pgYetiMaya", quiet=True) # Create Yeti cache nodes according to settings - settings = self.read_settings(self.fname) + path = self.filepath_from_context(context) + settings = self.read_settings(path) nodes = [] for node in settings["nodes"]: nodes.extend(self.create_node(namespace, node)) diff --git a/openpype/hosts/maya/plugins/load/load_yeti_rig.py b/openpype/hosts/maya/plugins/load/load_yeti_rig.py index b8066871b0..c9dfe9478b 100644 --- a/openpype/hosts/maya/plugins/load/load_yeti_rig.py +++ b/openpype/hosts/maya/plugins/load/load_yeti_rig.py @@ -20,9 +20,10 @@ class YetiRigLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): self, context, name=None, namespace=None, options=None ): group_name = options['group_name'] + path = self.filepath_from_context(context) with lib.maintained_selection(): file_url = self.prepare_root_value( - self.fname, context["project"]["name"] + path, context["project"]["name"] ) nodes = cmds.file( file_url, diff --git a/openpype/hosts/nuke/plugins/load/load_backdrop.py b/openpype/hosts/nuke/plugins/load/load_backdrop.py index 67c7877e60..f4f581e6a4 100644 --- a/openpype/hosts/nuke/plugins/load/load_backdrop.py +++ b/openpype/hosts/nuke/plugins/load/load_backdrop.py @@ -72,7 +72,7 @@ class LoadBackdropNodes(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") # adding nodes to node graph # just in case we are in group lets jump out of it diff --git a/openpype/hosts/nuke/plugins/load/load_camera_abc.py b/openpype/hosts/nuke/plugins/load/load_camera_abc.py index 40822c9eb7..951457475d 100644 --- a/openpype/hosts/nuke/plugins/load/load_camera_abc.py +++ b/openpype/hosts/nuke/plugins/load/load_camera_abc.py @@ -57,7 +57,7 @@ class AlembicCameraLoader(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") with maintained_selection(): camera_node = nuke.createNode( diff --git a/openpype/hosts/nuke/plugins/load/load_clip.py b/openpype/hosts/nuke/plugins/load/load_clip.py index 8f24fe6861..92f01e560a 100644 --- a/openpype/hosts/nuke/plugins/load/load_clip.py +++ b/openpype/hosts/nuke/plugins/load/load_clip.py @@ -99,7 +99,8 @@ class LoadClip(plugin.NukeLoader): representation = self._representation_with_hash_in_frame( representation ) - filepath = get_representation_path(representation).replace("\\", "/") + filepath = self.filepath_from_context(context) + filepath = filepath.replace("\\", "/") self.log.debug("_ filepath: {}".format(filepath)) start_at_workfile = options.get( @@ -154,7 +155,7 @@ class LoadClip(plugin.NukeLoader): read_node["file"].setValue(filepath) used_colorspace = self._set_colorspace( - read_node, version_data, representation["data"]) + read_node, version_data, representation["data"], filepath) self._set_range_to_node(read_node, first, last, start_at_workfile) @@ -306,8 +307,7 @@ class LoadClip(plugin.NukeLoader): # we will switch off undo-ing with viewer_update_and_undo_stop(): used_colorspace = self._set_colorspace( - read_node, version_data, representation["data"], - path=filepath) + read_node, version_data, representation["data"], filepath) self._set_range_to_node(read_node, first, last, start_at_workfile) @@ -454,9 +454,9 @@ class LoadClip(plugin.NukeLoader): return self.node_name_template.format(**name_data) - def _set_colorspace(self, node, version_data, repre_data, path=None): + def _set_colorspace(self, node, version_data, repre_data, path): output_color = None - path = path or self.fname.replace("\\", "/") + path = path.replace("\\", "/") # get colorspace colorspace = repre_data.get("colorspace") colorspace = colorspace or version_data.get("colorspace") diff --git a/openpype/hosts/nuke/plugins/load/load_effects.py b/openpype/hosts/nuke/plugins/load/load_effects.py index eb1c905c4d..6e56fe4a56 100644 --- a/openpype/hosts/nuke/plugins/load/load_effects.py +++ b/openpype/hosts/nuke/plugins/load/load_effects.py @@ -72,7 +72,7 @@ class LoadEffects(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") # getting data from json file with unicode conversion with open(file, "r") as f: diff --git a/openpype/hosts/nuke/plugins/load/load_effects_ip.py b/openpype/hosts/nuke/plugins/load/load_effects_ip.py index 03be8654ed..95452919e2 100644 --- a/openpype/hosts/nuke/plugins/load/load_effects_ip.py +++ b/openpype/hosts/nuke/plugins/load/load_effects_ip.py @@ -73,7 +73,7 @@ class LoadEffectsInputProcess(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") # getting data from json file with unicode conversion with open(file, "r") as f: diff --git a/openpype/hosts/nuke/plugins/load/load_gizmo.py b/openpype/hosts/nuke/plugins/load/load_gizmo.py index 2aa7c49723..c7a40e0d00 100644 --- a/openpype/hosts/nuke/plugins/load/load_gizmo.py +++ b/openpype/hosts/nuke/plugins/load/load_gizmo.py @@ -73,7 +73,7 @@ class LoadGizmo(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") # adding nodes to node graph # just in case we are in group lets jump out of it diff --git a/openpype/hosts/nuke/plugins/load/load_gizmo_ip.py b/openpype/hosts/nuke/plugins/load/load_gizmo_ip.py index 2514a28299..ceb8ee9609 100644 --- a/openpype/hosts/nuke/plugins/load/load_gizmo_ip.py +++ b/openpype/hosts/nuke/plugins/load/load_gizmo_ip.py @@ -75,7 +75,7 @@ class LoadGizmoInputProcess(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") # adding nodes to node graph # just in case we are in group lets jump out of it diff --git a/openpype/hosts/nuke/plugins/load/load_image.py b/openpype/hosts/nuke/plugins/load/load_image.py index 0a79ddada7..0ff39482d9 100644 --- a/openpype/hosts/nuke/plugins/load/load_image.py +++ b/openpype/hosts/nuke/plugins/load/load_image.py @@ -86,7 +86,7 @@ class LoadImage(load.LoaderPlugin): if namespace is None: namespace = context['asset']['name'] - file = self.fname + file = self.filepath_from_context(context) if not file: repr_id = context["representation"]["_id"] diff --git a/openpype/hosts/nuke/plugins/load/load_matchmove.py b/openpype/hosts/nuke/plugins/load/load_matchmove.py index a7d124d472..f942422c00 100644 --- a/openpype/hosts/nuke/plugins/load/load_matchmove.py +++ b/openpype/hosts/nuke/plugins/load/load_matchmove.py @@ -18,8 +18,9 @@ class MatchmoveLoader(load.LoaderPlugin): color = "orange" def load(self, context, name, namespace, data): - if self.fname.lower().endswith(".py"): - exec(open(self.fname).read()) + path = self.filepath_from_context(context) + if path.lower().endswith(".py"): + exec(open(path).read()) else: msg = "Unsupported script type" diff --git a/openpype/hosts/nuke/plugins/load/load_model.py b/openpype/hosts/nuke/plugins/load/load_model.py index 36781993ea..fad29d0d0b 100644 --- a/openpype/hosts/nuke/plugins/load/load_model.py +++ b/openpype/hosts/nuke/plugins/load/load_model.py @@ -55,7 +55,7 @@ class AlembicModelLoader(load.LoaderPlugin): data_imprint.update({k: version_data[k]}) # getting file path - file = self.fname.replace("\\", "/") + file = self.filepath_from_context(context).replace("\\", "/") with maintained_selection(): model_node = nuke.createNode( diff --git a/openpype/hosts/nuke/plugins/load/load_script_precomp.py b/openpype/hosts/nuke/plugins/load/load_script_precomp.py index b74fdf481a..7fd7c13c48 100644 --- a/openpype/hosts/nuke/plugins/load/load_script_precomp.py +++ b/openpype/hosts/nuke/plugins/load/load_script_precomp.py @@ -43,8 +43,8 @@ class LinkAsGroup(load.LoaderPlugin): if namespace is None: namespace = context['asset']['name'] - file = self.fname.replace("\\", "/") - self.log.info("file: {}\n".format(self.fname)) + file = self.filepath_from_context(context).replace("\\", "/") + self.log.info("file: {}\n".format(file)) precomp_name = context["representation"]["context"]["subset"] diff --git a/openpype/hosts/photoshop/api/README.md b/openpype/hosts/photoshop/api/README.md index 4a36746cb2..7bd2bcb1bf 100644 --- a/openpype/hosts/photoshop/api/README.md +++ b/openpype/hosts/photoshop/api/README.md @@ -210,8 +210,9 @@ class ImageLoader(load.LoaderPlugin): representations = ["*"] def load(self, context, name=None, namespace=None, data=None): + path = self.filepath_from_context(context) with photoshop.maintained_selection(): - layer = stub.import_smart_object(self.fname) + layer = stub.import_smart_object(path) self[:] = [layer] diff --git a/openpype/hosts/photoshop/plugins/load/load_image.py b/openpype/hosts/photoshop/plugins/load/load_image.py index 91a9787781..eb770bbd20 100644 --- a/openpype/hosts/photoshop/plugins/load/load_image.py +++ b/openpype/hosts/photoshop/plugins/load/load_image.py @@ -22,7 +22,8 @@ class ImageLoader(photoshop.PhotoshopLoader): name ) with photoshop.maintained_selection(): - layer = self.import_layer(self.fname, layer_name, stub) + path = self.filepath_from_context(context) + layer = self.import_layer(path, layer_name, stub) self[:] = [layer] namespace = namespace or layer_name diff --git a/openpype/hosts/photoshop/plugins/load/load_image_from_sequence.py b/openpype/hosts/photoshop/plugins/load/load_image_from_sequence.py index c25c5a8f2c..f9fceb80bb 100644 --- a/openpype/hosts/photoshop/plugins/load/load_image_from_sequence.py +++ b/openpype/hosts/photoshop/plugins/load/load_image_from_sequence.py @@ -29,11 +29,13 @@ class ImageFromSequenceLoader(photoshop.PhotoshopLoader): options = [] def load(self, context, name=None, namespace=None, data=None): + + path = self.filepath_from_context(context) if data.get("frame"): - self.fname = os.path.join( - os.path.dirname(self.fname), data["frame"] + path = os.path.join( + os.path.dirname(path), data["frame"] ) - if not os.path.exists(self.fname): + if not os.path.exists(path): return stub = self.get_stub() @@ -42,7 +44,7 @@ class ImageFromSequenceLoader(photoshop.PhotoshopLoader): ) with photoshop.maintained_selection(): - layer = stub.import_smart_object(self.fname, layer_name) + layer = stub.import_smart_object(path, layer_name) self[:] = [layer] namespace = namespace or layer_name diff --git a/openpype/hosts/photoshop/plugins/load/load_reference.py b/openpype/hosts/photoshop/plugins/load/load_reference.py index 1f32a5d23c..5772e243d5 100644 --- a/openpype/hosts/photoshop/plugins/load/load_reference.py +++ b/openpype/hosts/photoshop/plugins/load/load_reference.py @@ -23,7 +23,8 @@ class ReferenceLoader(photoshop.PhotoshopLoader): stub.get_layers(), context["asset"]["name"], name ) with photoshop.maintained_selection(): - layer = self.import_layer(self.fname, layer_name, stub) + path = self.filepath_from_context(context) + layer = self.import_layer(path, layer_name, stub) self[:] = [layer] namespace = namespace or layer_name diff --git a/openpype/hosts/resolve/api/plugin.py b/openpype/hosts/resolve/api/plugin.py index e5846c2fc2..59c27f29da 100644 --- a/openpype/hosts/resolve/api/plugin.py +++ b/openpype/hosts/resolve/api/plugin.py @@ -291,7 +291,7 @@ class ClipLoader: active_bin = None data = dict() - def __init__(self, cls, context, **options): + def __init__(self, cls, context, path, **options): """ Initialize object Arguments: @@ -304,6 +304,7 @@ class ClipLoader: self.__dict__.update(cls.__dict__) self.context = context self.active_project = lib.get_current_project() + self.fname = path # try to get value from options or evaluate key value for `handles` self.with_handles = options.get("handles") or bool( diff --git a/openpype/hosts/resolve/plugins/load/load_clip.py b/openpype/hosts/resolve/plugins/load/load_clip.py index 05bfb003d6..3518597e8c 100644 --- a/openpype/hosts/resolve/plugins/load/load_clip.py +++ b/openpype/hosts/resolve/plugins/load/load_clip.py @@ -55,8 +55,9 @@ class LoadClip(plugin.TimelineItemLoader): }) # load clip to timeline and get main variables + path = self.filepath_from_context(context) timeline_item = plugin.ClipLoader( - self, context, **options).load() + self, context, path, **options).load() namespace = namespace or timeline_item.GetName() version = context['version'] version_data = version.get("data", {}) @@ -115,10 +116,10 @@ class LoadClip(plugin.TimelineItemLoader): version_name = version.get("name", None) colorspace = version_data.get("colorspace", None) object_name = "{}_{}".format(name, namespace) - self.fname = get_representation_path(representation) + path = get_representation_path(representation) context["version"] = {"data": version_data} - loader = plugin.ClipLoader(self, context) + loader = plugin.ClipLoader(self, context, path) timeline_item = loader.update(timeline_item) # add additional metadata from the version to imprint Avalon knob diff --git a/openpype/hosts/tvpaint/plugins/load/load_image.py b/openpype/hosts/tvpaint/plugins/load/load_image.py index 5283d04355..a400738019 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_image.py +++ b/openpype/hosts/tvpaint/plugins/load/load_image.py @@ -77,8 +77,9 @@ class ImportImage(plugin.Loader): ) # Fill import script with filename and layer name # - filename mus not contain backwards slashes + path = self.filepath_from_context(context).replace("\\", "/") george_script = self.import_script.format( - self.fname.replace("\\", "/"), + path, layer_name, load_options_str ) diff --git a/openpype/hosts/tvpaint/plugins/load/load_reference_image.py b/openpype/hosts/tvpaint/plugins/load/load_reference_image.py index 7f7a68cc41..edc116a8e4 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_reference_image.py +++ b/openpype/hosts/tvpaint/plugins/load/load_reference_image.py @@ -86,10 +86,12 @@ class LoadImage(plugin.Loader): subset_name = context["subset"]["name"] layer_name = self.get_unique_layer_name(asset_name, subset_name) + path = self.filepath_from_context(context) + # Fill import script with filename and layer name # - filename mus not contain backwards slashes george_script = self.import_script.format( - self.fname.replace("\\", "/"), + path.replace("\\", "/"), layer_name, load_options_str ) @@ -271,9 +273,6 @@ class LoadImage(plugin.Loader): # Remove old layers self._remove_layers(layer_ids=layer_ids_to_remove) - # Change `fname` to new representation - self.fname = self.filepath_from_context(context) - name = container["name"] namespace = container["namespace"] new_container = self.load(context, name, namespace, {}) diff --git a/openpype/hosts/tvpaint/plugins/load/load_sound.py b/openpype/hosts/tvpaint/plugins/load/load_sound.py index f312db262a..3003280eef 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_sound.py +++ b/openpype/hosts/tvpaint/plugins/load/load_sound.py @@ -60,9 +60,10 @@ class ImportSound(plugin.Loader): output_filepath = output_file.name.replace("\\", "/") # Prepare george script + path = self.filepath_from_context(context).replace("\\", "/") import_script = "\n".join(self.import_script_lines) george_script = import_script.format( - self.fname.replace("\\", "/"), + path, output_filepath ) self.log.info("*** George script:\n{}\n***".format(george_script)) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index fc7588f56e..9492d3d5eb 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -31,18 +31,18 @@ class LoadWorkfile(plugin.Loader): def load(self, context, name, namespace, options): # Load context of current workfile as first thing # - which context and extension has - host = registered_host() - current_file = host.get_current_workfile() - - context = get_current_workfile_context() - - filepath = self.fname.replace("\\", "/") + filepath = self.filepath_from_context(context) + filepath = filepath.replace("\\", "/") if not os.path.exists(filepath): raise FileExistsError( "The loaded file does not exist. Try downloading it first." ) + host = registered_host() + current_file = host.get_current_workfile() + work_context = get_current_workfile_context() + george_script = "tv_LoadProject '\"'\"{}\"'\"'".format( filepath ) @@ -50,10 +50,10 @@ class LoadWorkfile(plugin.Loader): # Save workfile. host_name = "tvpaint" - project_name = context.get("project") - asset_name = context.get("asset") - task_name = context.get("task") - # Far cases when there is workfile without context + project_name = work_context.get("project") + asset_name = work_context.get("asset") + task_name = work_context.get("task") + # Far cases when there is workfile without work_context if not asset_name: project_name = legacy_io.active_project() asset_name = legacy_io.Session["AVALON_ASSET"] diff --git a/openpype/hosts/unreal/plugins/load/load_alembic_animation.py b/openpype/hosts/unreal/plugins/load/load_alembic_animation.py index 52eea4122a..cb60197a4c 100644 --- a/openpype/hosts/unreal/plugins/load/load_alembic_animation.py +++ b/openpype/hosts/unreal/plugins/load/load_alembic_animation.py @@ -87,7 +87,8 @@ class AnimationAlembicLoader(plugin.Loader): if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir): unreal.EditorAssetLibrary.make_directory(asset_dir) - task = self.get_task(self.fname, asset_dir, asset_name, False) + path = self.filepath_from_context(context) + task = self.get_task(path, asset_dir, asset_name, False) asset_tools = unreal.AssetToolsHelpers.get_asset_tools() asset_tools.import_asset_tasks([task]) diff --git a/openpype/hosts/unreal/plugins/load/load_animation.py b/openpype/hosts/unreal/plugins/load/load_animation.py index a5ecb677e8..7ed85ee411 100644 --- a/openpype/hosts/unreal/plugins/load/load_animation.py +++ b/openpype/hosts/unreal/plugins/load/load_animation.py @@ -26,7 +26,7 @@ class AnimationFBXLoader(plugin.Loader): icon = "cube" color = "orange" - def _process(self, asset_dir, asset_name, instance_name): + def _process(self, path, asset_dir, asset_name, instance_name): automated = False actor = None @@ -55,7 +55,7 @@ class AnimationFBXLoader(plugin.Loader): asset_doc = get_current_project_asset(fields=["data.fps"]) - task.set_editor_property('filename', self.fname) + task.set_editor_property('filename', path) task.set_editor_property('destination_path', asset_dir) task.set_editor_property('destination_name', asset_name) task.set_editor_property('replace_existing', False) @@ -177,14 +177,15 @@ class AnimationFBXLoader(plugin.Loader): EditorAssetLibrary.make_directory(asset_dir) - libpath = self.fname.replace("fbx", "json") + path = self.filepath_from_context(context) + libpath = path.replace(".fbx", ".json") with open(libpath, "r") as fp: data = json.load(fp) instance_name = data.get("instance_name") - animation = self._process(asset_dir, asset_name, instance_name) + animation = self._process(path, asset_dir, asset_name, instance_name) asset_content = EditorAssetLibrary.list_assets( hierarchy_dir, recursive=True, include_folder=False) diff --git a/openpype/hosts/unreal/plugins/load/load_camera.py b/openpype/hosts/unreal/plugins/load/load_camera.py index 59ea14697d..3d98b3d8e1 100644 --- a/openpype/hosts/unreal/plugins/load/load_camera.py +++ b/openpype/hosts/unreal/plugins/load/load_camera.py @@ -200,12 +200,13 @@ class CameraLoader(plugin.Loader): settings.set_editor_property('reduce_keys', False) if cam_seq: + path = self.filepath_from_context(context) self._import_camera( EditorLevelLibrary.get_editor_world(), cam_seq, cam_seq.get_bindings(), settings, - self.fname + path ) # Set range of all sections diff --git a/openpype/hosts/unreal/plugins/load/load_geometrycache_abc.py b/openpype/hosts/unreal/plugins/load/load_geometrycache_abc.py index 3a292fdbd1..13ba236a7d 100644 --- a/openpype/hosts/unreal/plugins/load/load_geometrycache_abc.py +++ b/openpype/hosts/unreal/plugins/load/load_geometrycache_abc.py @@ -111,8 +111,9 @@ class PointCacheAlembicLoader(plugin.Loader): if frame_start == frame_end: frame_end += 1 + path = self.filepath_from_context(context) task = self.get_task( - self.fname, asset_dir, asset_name, False, frame_start, frame_end) + path, asset_dir, asset_name, False, frame_start, frame_end) unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) # noqa: E501 diff --git a/openpype/hosts/unreal/plugins/load/load_layout.py b/openpype/hosts/unreal/plugins/load/load_layout.py index 86b2e1456c..e9f3c79960 100644 --- a/openpype/hosts/unreal/plugins/load/load_layout.py +++ b/openpype/hosts/unreal/plugins/load/load_layout.py @@ -618,7 +618,8 @@ class LayoutLoader(plugin.Loader): EditorLevelLibrary.load_level(level) - loaded_assets = self._process(self.fname, asset_dir, shot) + path = self.filepath_from_context(context) + loaded_assets = self._process(path, asset_dir, shot) for s in sequences: EditorAssetLibrary.save_asset(s.get_path_name()) diff --git a/openpype/hosts/unreal/plugins/load/load_layout_existing.py b/openpype/hosts/unreal/plugins/load/load_layout_existing.py index 929a9a1399..32fff84152 100644 --- a/openpype/hosts/unreal/plugins/load/load_layout_existing.py +++ b/openpype/hosts/unreal/plugins/load/load_layout_existing.py @@ -380,7 +380,8 @@ class ExistingLayoutLoader(plugin.Loader): raise AssertionError("Current level not saved") project_name = context["project"]["name"] - containers = self._process(self.fname, project_name) + path = self.filepath_from_context(context) + containers = self._process(path, project_name) curr_level_path = Path( curr_level.get_outer().get_path_name()).parent.as_posix() diff --git a/openpype/hosts/unreal/plugins/load/load_skeletalmesh_abc.py b/openpype/hosts/unreal/plugins/load/load_skeletalmesh_abc.py index 7591d5582f..0b0030ff77 100644 --- a/openpype/hosts/unreal/plugins/load/load_skeletalmesh_abc.py +++ b/openpype/hosts/unreal/plugins/load/load_skeletalmesh_abc.py @@ -89,7 +89,8 @@ class SkeletalMeshAlembicLoader(plugin.Loader): if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir): unreal.EditorAssetLibrary.make_directory(asset_dir) - task = self.get_task(self.fname, asset_dir, asset_name, False) + path = self.filepath_from_context(context) + task = self.get_task(path, asset_dir, asset_name, False) unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) # noqa: E501 diff --git a/openpype/hosts/unreal/plugins/load/load_skeletalmesh_fbx.py b/openpype/hosts/unreal/plugins/load/load_skeletalmesh_fbx.py index e9676cde3a..09cd37b9db 100644 --- a/openpype/hosts/unreal/plugins/load/load_skeletalmesh_fbx.py +++ b/openpype/hosts/unreal/plugins/load/load_skeletalmesh_fbx.py @@ -23,7 +23,7 @@ class SkeletalMeshFBXLoader(plugin.Loader): def load(self, context, name, namespace, options): """Load and containerise representation into Content Browser. - This is two step process. First, import FBX to temporary path and + This is a two step process. First, import FBX to temporary path and then call `containerise()` on it - this moves all content to new directory and then it will create AssetContainer there and imprint it with metadata. This will mark this path as container. @@ -65,7 +65,8 @@ class SkeletalMeshFBXLoader(plugin.Loader): task = unreal.AssetImportTask() - task.set_editor_property('filename', self.fname) + path = self.filepath_from_context(context) + task.set_editor_property('filename', path) task.set_editor_property('destination_path', asset_dir) task.set_editor_property('destination_name', asset_name) task.set_editor_property('replace_existing', False) diff --git a/openpype/hosts/unreal/plugins/load/load_staticmesh_abc.py b/openpype/hosts/unreal/plugins/load/load_staticmesh_abc.py index befc7b0ac9..98e6d962b1 100644 --- a/openpype/hosts/unreal/plugins/load/load_staticmesh_abc.py +++ b/openpype/hosts/unreal/plugins/load/load_staticmesh_abc.py @@ -98,8 +98,9 @@ class StaticMeshAlembicLoader(plugin.Loader): if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir): unreal.EditorAssetLibrary.make_directory(asset_dir) + path = self.filepath_from_context(context) task = self.get_task( - self.fname, asset_dir, asset_name, False, default_conversion) + path, asset_dir, asset_name, False, default_conversion) unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) # noqa: E501 diff --git a/openpype/hosts/unreal/plugins/load/load_staticmesh_fbx.py b/openpype/hosts/unreal/plugins/load/load_staticmesh_fbx.py index e416256486..fa26e252f5 100644 --- a/openpype/hosts/unreal/plugins/load/load_staticmesh_fbx.py +++ b/openpype/hosts/unreal/plugins/load/load_staticmesh_fbx.py @@ -88,7 +88,8 @@ class StaticMeshFBXLoader(plugin.Loader): unreal.EditorAssetLibrary.make_directory(asset_dir) - task = self.get_task(self.fname, asset_dir, asset_name, False) + path = self.filepath_from_context(context) + task = self.get_task(path, asset_dir, asset_name, False) unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) # noqa: E501 diff --git a/openpype/hosts/unreal/plugins/load/load_uasset.py b/openpype/hosts/unreal/plugins/load/load_uasset.py index 30f63abe39..88aaac41e8 100644 --- a/openpype/hosts/unreal/plugins/load/load_uasset.py +++ b/openpype/hosts/unreal/plugins/load/load_uasset.py @@ -64,8 +64,9 @@ class UAssetLoader(plugin.Loader): destination_path = asset_dir.replace( "/Game", Path(unreal.Paths.project_content_dir()).as_posix(), 1) + path = self.filepath_from_context(context) shutil.copy( - self.fname, + path, f"{destination_path}/{name}_{unique_number:02}.{self.extension}") # Create Asset Container diff --git a/openpype/pipeline/load/plugins.py b/openpype/pipeline/load/plugins.py index e380d65bbe..f87fb3312d 100644 --- a/openpype/pipeline/load/plugins.py +++ b/openpype/pipeline/load/plugins.py @@ -39,9 +39,6 @@ class LoaderPlugin(list): log = logging.getLogger("SubsetLoader") log.propagate = True - def __init__(self, context): - self.fname = self.filepath_from_context(context) - @classmethod def apply_settings(cls, project_settings, system_settings): host_name = os.environ.get("AVALON_APP") @@ -246,9 +243,6 @@ class SubsetLoaderPlugin(LoaderPlugin): namespace (str, optional): Use pre-defined namespace """ - def __init__(self, context): - pass - def discover_loader_plugins(project_name=None): from openpype.lib import Logger diff --git a/openpype/pipeline/load/utils.py b/openpype/pipeline/load/utils.py index 2c40280ccd..42418be40e 100644 --- a/openpype/pipeline/load/utils.py +++ b/openpype/pipeline/load/utils.py @@ -314,7 +314,12 @@ def load_with_repre_context( ) ) - loader = Loader(repre_context) + loader = Loader() + + # Backwards compatibility: Originally the loader's __init__ required the + # representation context to set `fname` attribute to the filename to load + loader.fname = get_representation_path_from_context(repre_context) + return loader.load(repre_context, name, namespace, options) @@ -338,8 +343,7 @@ def load_with_subset_context( ) ) - loader = Loader(subset_context) - return loader.load(subset_context, name, namespace, options) + return Loader().load(subset_context, name, namespace, options) def load_with_subset_contexts( @@ -364,8 +368,7 @@ def load_with_subset_contexts( "Running '{}' on '{}'".format(Loader.__name__, joined_subset_names) ) - loader = Loader(subset_contexts) - return loader.load(subset_contexts, name, namespace, options) + return Loader().load(subset_contexts, name, namespace, options) def load_container( @@ -447,8 +450,7 @@ def remove_container(container): .format(container.get("loader")) ) - loader = Loader(get_representation_context(container["representation"])) - return loader.remove(container) + return Loader().remove(container) def update_container(container, version=-1): @@ -498,8 +500,7 @@ def update_container(container, version=-1): .format(container.get("loader")) ) - loader = Loader(get_representation_context(container["representation"])) - return loader.update(container, new_representation) + return Loader().update(container, new_representation) def switch_container(container, representation, loader_plugin=None): @@ -635,7 +636,7 @@ def get_representation_path(representation, root=None, dbcon=None): root = registered_root() - def path_from_represenation(): + def path_from_representation(): try: template = representation["data"]["template"] except KeyError: @@ -759,7 +760,7 @@ def get_representation_path(representation, root=None, dbcon=None): return os.path.normpath(path) return ( - path_from_represenation() or + path_from_representation() or path_from_config() or path_from_data() ) diff --git a/openpype/plugins/load/copy_file.py b/openpype/plugins/load/copy_file.py index 163f56a83a..7fd56c8a6a 100644 --- a/openpype/plugins/load/copy_file.py +++ b/openpype/plugins/load/copy_file.py @@ -14,8 +14,9 @@ class CopyFile(load.LoaderPlugin): color = get_default_entity_icon_color() def load(self, context, name=None, namespace=None, data=None): - self.log.info("Added copy to clipboard: {0}".format(self.fname)) - self.copy_file_to_clipboard(self.fname) + path = self.filepath_from_context(context) + self.log.info("Added copy to clipboard: {0}".format(path)) + self.copy_file_to_clipboard(path) @staticmethod def copy_file_to_clipboard(path): diff --git a/openpype/plugins/load/copy_file_path.py b/openpype/plugins/load/copy_file_path.py index 569e5c8780..b055494e85 100644 --- a/openpype/plugins/load/copy_file_path.py +++ b/openpype/plugins/load/copy_file_path.py @@ -14,8 +14,9 @@ class CopyFilePath(load.LoaderPlugin): color = "#999999" def load(self, context, name=None, namespace=None, data=None): - self.log.info("Added file path to clipboard: {0}".format(self.fname)) - self.copy_path_to_clipboard(self.fname) + path = self.filepath_from_context(context) + self.log.info("Added file path to clipboard: {0}".format(path)) + self.copy_path_to_clipboard(path) @staticmethod def copy_path_to_clipboard(path): diff --git a/openpype/plugins/load/open_djv.py b/openpype/plugins/load/open_djv.py index 9c36e7f405..5c679f6a51 100644 --- a/openpype/plugins/load/open_djv.py +++ b/openpype/plugins/load/open_djv.py @@ -33,9 +33,11 @@ class OpenInDJV(load.LoaderPlugin): color = "orange" def load(self, context, name, namespace, data): - directory = os.path.dirname(self.fname) import clique + path = self.filepath_from_context(context) + directory = os.path.dirname(path) + pattern = clique.PATTERNS["frames"] files = os.listdir(directory) collections, remainder = clique.assemble( @@ -48,7 +50,7 @@ class OpenInDJV(load.LoaderPlugin): sequence = collections[0] first_image = list(sequence)[0] else: - first_image = self.fname + first_image = path filepath = os.path.normpath(os.path.join(directory, first_image)) self.log.info("Opening : {}".format(filepath)) diff --git a/openpype/plugins/load/open_file.py b/openpype/plugins/load/open_file.py index 00b2ecd7c5..5c4f4901d1 100644 --- a/openpype/plugins/load/open_file.py +++ b/openpype/plugins/load/open_file.py @@ -28,7 +28,7 @@ class OpenFile(load.LoaderPlugin): def load(self, context, name, namespace, data): - path = self.fname + path = self.filepath_from_context(context) if not os.path.exists(path): raise RuntimeError("File not found: {}".format(path)) diff --git a/website/docs/dev_colorspace.md b/website/docs/dev_colorspace.md index c4b8e74d73..cb07cb18a0 100644 --- a/website/docs/dev_colorspace.md +++ b/website/docs/dev_colorspace.md @@ -80,7 +80,7 @@ from openpype.pipeline.colorspace import ( class YourLoader(api.Loader): def load(self, context, name=None, namespace=None, options=None): - path = self.fname + path = self.filepath_from_context(context) colorspace_data = context["representation"]["data"].get("colorspaceData", {}) colorspace = ( colorspace_data.get("colorspace")