process custom reference naming for maya

This commit is contained in:
Thomas Fricard 2023-02-02 12:28:09 +01:00
parent 6ceb7ef8b3
commit 1c207b91f4
2 changed files with 27 additions and 4 deletions

View file

@ -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

View file

@ -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)