From 1c207b91f40031e030df0842c1ca009b2588043e Mon Sep 17 00:00:00 2001 From: Thomas Fricard Date: Thu, 2 Feb 2023 12:28:09 +0100 Subject: [PATCH] process custom reference naming for maya --- openpype/hosts/maya/api/plugin.py | 26 +++++++++++++++++-- .../hosts/maya/plugins/load/load_reference.py | 5 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/maya/api/plugin.py b/openpype/hosts/maya/api/plugin.py index 98d6492003..61966a049c 100644 --- a/openpype/hosts/maya/api/plugin.py +++ b/openpype/hosts/maya/api/plugin.py @@ -143,16 +143,37 @@ class ReferenceLoader(Loader): assert os.path.exists(self.fname), "%s does not exist." % self.fname asset = context['asset'] + subset = context['subset'] + settings = get_project_settings(os.environ['AVALON_PROJECT']) loaded_containers = [] count = options.get("count") or 1 for c in range(0, count): namespace = namespace or lib.unique_namespace( - "{}:{}_".format(asset["name"], context["subset"]["name"]), + "{}_{}_".format(asset["name"], context["subset"]["name"]), prefix="_" if asset["name"][0].isdigit() else "", suffix="_", ) + custom_naming = settings['maya']['load']['reference_loader']['naming'] # noqa + group_name = None + + if custom_naming: + custom_naming = custom_naming.format( + asset=asset, + subset=subset + ) + if ':' in custom_naming: + if custom_naming[0] == ':': + group_name = "{}{}".format(namespace, custom_naming) + elif custom_naming[-1] == ':': + namespace = custom_naming.split(':')[0] + else: + namespace = custom_naming.split(':')[0] + group_name = custom_naming + else: + namespace = custom_naming + # Offset loaded subset if "offset" in options: offset = [i * c for i in options["offset"]] @@ -164,7 +185,8 @@ class ReferenceLoader(Loader): context=context, name=name, namespace=namespace, - options=options + options=options, + group_name=group_name ) # Only containerize if any nodes were loaded by the Loader diff --git a/openpype/hosts/maya/plugins/load/load_reference.py b/openpype/hosts/maya/plugins/load/load_reference.py index a206b63b46..cca45edbad 100644 --- a/openpype/hosts/maya/plugins/load/load_reference.py +++ b/openpype/hosts/maya/plugins/load/load_reference.py @@ -117,7 +117,7 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): # Name of creator class that will be used to create animation instance animation_creator_name = "CreateAnimation" - def process_reference(self, context, name, namespace, options): + def process_reference(self, context, name, namespace, options, group_name=None): # noqa import maya.cmds as cmds try: @@ -125,7 +125,8 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader): except ValueError: family = "model" - group_name = "{}_GRP".format(namespace) + if not group_name: + group_name = "{}:_GRP".format(namespace) # True by default to keep legacy behaviours attach_to_root = options.get("attach_to_root", True)