Maya: do not create top level group on reference (#5402)

* OP-6358 - allow not creation of group for reference loader in Maya

Creation of wrapping group could be controlled by checkbox in ReferenceLoader options.

* OP-6358 - group name could be empty in Settings

This enables default behavior of not creating wrapping group without need of artists unchecking `Group imported assets`.

* OP-6358 - changed to safer logic

Stripping of | was weird and potentially dangerous (collision of names), this logic should be safer.
This commit is contained in:
Petr Kalis 2023-08-08 11:00:02 +02:00 committed by GitHub
parent ee006f8d01
commit 7d40debd64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View file

@ -575,8 +575,8 @@ class ReferenceLoader(Loader):
raise LoadError("No namespace specified in "
"Maya ReferenceLoader settings")
elif not custom_naming['group_name']:
raise LoadError("No group name specified in "
"Maya ReferenceLoader settings")
self.log.debug("No custom group_name, no group will be created.")
options["attach_to_root"] = False
formatting_data = {
"asset_name": asset['name'],

View file

@ -9,7 +9,8 @@ from openpype.hosts.maya.api.lib import (
maintained_selection,
get_container_members,
parent_nodes,
create_rig_animation_instance
create_rig_animation_instance,
get_reference_node
)
@ -123,6 +124,10 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
attach_to_root = options.get("attach_to_root", True)
group_name = options["group_name"]
# no group shall be created
if not attach_to_root:
group_name = namespace
path = self.filepath_from_context(context)
with maintained_selection():
cmds.loadPlugin("AbcImport.mll", quiet=True)
@ -148,11 +153,10 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
if current_namespace != ":":
group_name = current_namespace + ":" + group_name
group_name = "|" + group_name
self[:] = new_nodes
if attach_to_root:
group_name = "|" + group_name
roots = cmds.listRelatives(group_name,
children=True,
fullPath=True) or []
@ -205,6 +209,11 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
self._post_process_rig(name, namespace, context, options)
else:
if "translate" in options:
if not attach_to_root and new_nodes:
root_nodes = cmds.ls(new_nodes, assemblies=True,
long=True)
# we assume only a single root is ever loaded
group_name = root_nodes[0]
cmds.setAttr("{}.translate".format(group_name),
*options["translate"])
return new_nodes

View file

@ -113,7 +113,8 @@ This is useful to fix some specific renderer glitches and advanced hacking of Ma
#### Namespace and Group Name
Here you can create your own custom naming for the reference loader.
The custom naming is split into two parts: namespace and group name. If you don't set the namespace or the group name, an error will occur.
The custom naming is split into two parts: namespace and group name. If you don't set the namespace, an error will occur.
Group name could be set empty, that way no wrapping group will be created for loaded item.
Here's the different variables you can use:
<div class="row markdown">