From 2a42f9b27cb508a153325525e0175caa412b7110 Mon Sep 17 00:00:00 2001 From: aardschok Date: Thu, 2 Nov 2017 15:06:20 +0100 Subject: [PATCH 1/2] implemented ImportModelLoader to import assets (.ma) --- colorbleed/plugins/maya/load/load_model.py | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/colorbleed/plugins/maya/load/load_model.py b/colorbleed/plugins/maya/load/load_model.py index 9b17a1ae47..22caac8c2c 100644 --- a/colorbleed/plugins/maya/load/load_model.py +++ b/colorbleed/plugins/maya/load/load_model.py @@ -31,6 +31,104 @@ class ModelLoader(colorbleed.maya.plugin.ReferenceLoader): return nodes +class ImportModelLoader(api.Loader): + """An ImportModelLoader for Maya + + This will implement the basic behavior for a loader to inherit from that + will containerize content. The loader will not be able to use `update` + but only `remove`. When calling the `update` the loader will return a + "NotImplementedError". + + """ + + families = ["colorbleed.model"] + representations = ["ma"] + + label = "Import Model" + order = -10 + icon = "code-fork" + color = "orange" + + def load(self, context, name=None, namespace=None, data=None): + + import maya.cmds as cmds + + from avalon import maya + from avalon.maya import lib + from avalon.maya.pipeline import containerise + + asset = context['asset'] + + namespace = namespace or lib.unique_namespace( + asset["name"] + "_", + prefix="_" if asset["name"][0].isdigit() else "", + suffix="_", + ) + + with maya.maintained_selection(): + nodes = cmds.file(self.fname, + i=True, + namespace=namespace, + returnNewNodes=True, + groupReference=True, + groupName="{}:{}".format(namespace, name)) + + # Only containerize if any nodes were loaded by the Loader + if not nodes: + return + + self[:] = nodes + + return containerise( + name=name, + namespace=namespace, + nodes=nodes, + context=context, + loader=self.__class__.__name__) + + def update(self, container, representation): + from avalon.vendor.Qt import QtWidgets + + message = ("The content of this asset was imported. " + "We cannot update this because we will need" + " to keep insane amount of things in mind.\n" + "Please remove and reimport the asset." + "\n\nIf you really need to update a lot we " + "recommend referencing.") + + QtWidgets.QMessageBox.critical(None, + "Can't update", + message, + QtWidgets.QMessageBox.Ok) + + return + + def remove(self, container): + + from maya import cmds + + namespace = container["namespace"] + container_name = container["objectName"] + + self.log.info("Removing '%s' from Maya.." % container["name"]) + + container_content = cmds.sets(container_name, query=True) + nodes = cmds.ls(container_content, long=True) + relatives = cmds.listRelatives(nodes, + ad=True, + fullPath=True) or [] + + nodes += relatives + + try: + cmds.delete(nodes) + except ValueError: + # Already implicitly deleted by Maya upon removing reference + pass + + cmds.namespace(removeNamespace=namespace, deleteNamespaceContent=True) + + class GpuCacheLoader(api.Loader): """Load model Alembic as gpuCache""" From 6647c19e92b9c44553d6edb079f719a0d545b508 Mon Sep 17 00:00:00 2001 From: aardschok Date: Thu, 2 Nov 2017 15:36:23 +0100 Subject: [PATCH 2/2] removed relatives query --- colorbleed/plugins/maya/load/load_model.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/colorbleed/plugins/maya/load/load_model.py b/colorbleed/plugins/maya/load/load_model.py index 22caac8c2c..ff512610a3 100644 --- a/colorbleed/plugins/maya/load/load_model.py +++ b/colorbleed/plugins/maya/load/load_model.py @@ -45,9 +45,9 @@ class ImportModelLoader(api.Loader): representations = ["ma"] label = "Import Model" - order = -10 - icon = "code-fork" - color = "orange" + order = 10 + icon = "arrow-circle-down" + color = "white" def load(self, context, name=None, namespace=None, data=None): @@ -114,11 +114,8 @@ class ImportModelLoader(api.Loader): container_content = cmds.sets(container_name, query=True) nodes = cmds.ls(container_content, long=True) - relatives = cmds.listRelatives(nodes, - ad=True, - fullPath=True) or [] - nodes += relatives + nodes.append(container_name) try: cmds.delete(nodes)