OP-2790 - added clean_import option to Maya's Import loader

By selecting this option all occurrences of cbId of imported nodes will be removed.
This commit is contained in:
Petr Kalis 2022-05-13 15:16:46 +02:00
parent 6156553486
commit 6a75497bfc

View file

@ -1,7 +1,7 @@
"""A module containing generic loader actions that will display in the Loader.
"""
import qargparse
from openpype.pipeline import load
from openpype.hosts.maya.api.lib import (
maintained_selection,
@ -98,6 +98,15 @@ class ImportMayaLoader(load.LoaderPlugin):
icon = "arrow-circle-down"
color = "#775555"
options = [
qargparse.Boolean(
"clean_import",
label="Clean import",
default=False,
help="Should all occurences of cbId be purged?"
)
]
def load(self, context, name=None, namespace=None, data=None):
import maya.cmds as cmds
@ -105,6 +114,8 @@ class ImportMayaLoader(load.LoaderPlugin):
if choice is False:
return
clean_import = data.get("clean_import", False)
asset = context['asset']
namespace = namespace or unique_namespace(
@ -114,13 +125,21 @@ class ImportMayaLoader(load.LoaderPlugin):
)
with maintained_selection():
cmds.file(self.fname,
i=True,
preserveReferences=True,
namespace=namespace,
returnNewNodes=True,
groupReference=True,
groupName="{}:{}".format(namespace, name))
nodes = cmds.file(self.fname,
i=True,
preserveReferences=True,
namespace=namespace,
returnNewNodes=True,
groupReference=True,
groupName="{}:{}".format(namespace, name))
if clean_import:
shapes = cmds.ls(nodes, shapes=True, long=True)
for shape in shapes:
meshes = cmds.ls('{}.cbId'.format(shape))
for mesh in meshes:
print("Removing ... " + (mesh))
cmds.deleteAttr(mesh)
# We do not containerize imported content, it remains unmanaged
return