From 2c8a4eca64a81705b5d06cb60fd10436010a666d Mon Sep 17 00:00:00 2001 From: aardschok Date: Wed, 2 Aug 2017 10:37:19 +0200 Subject: [PATCH] updated loader to create a nice namespace --- .../plugins/maya/load/load_animation.py | 1 - colorbleed/plugins/maya/load/load_model.py | 40 ++++++++++--------- colorbleed/plugins/maya/load/load_rig.py | 1 + 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/colorbleed/plugins/maya/load/load_animation.py b/colorbleed/plugins/maya/load/load_animation.py index 6ef3d07110..e48b29ef62 100644 --- a/colorbleed/plugins/maya/load/load_animation.py +++ b/colorbleed/plugins/maya/load/load_animation.py @@ -23,7 +23,6 @@ class AbcLoader(api.Loader): # Create unique namespace for the cameras # Get name from asset being loaded - assert "_" in name, "Naming convention not followed" assetname = "{}_".format(name.split("_")[0]) namespace = maya.unique_namespace(assetname, format="%03d", diff --git a/colorbleed/plugins/maya/load/load_model.py b/colorbleed/plugins/maya/load/load_model.py index ad70ad3440..f81174c14e 100644 --- a/colorbleed/plugins/maya/load/load_model.py +++ b/colorbleed/plugins/maya/load/load_model.py @@ -1,7 +1,7 @@ -from maya import cmds +import maya.cmds as cmds from avalon import api -from avalon import maya +import avalon.maya class ModelLoader(api.Loader): @@ -10,22 +10,26 @@ class ModelLoader(api.Loader): families = ["colorbleed.model"] representations = ["ma"] - label = "Reference model" + label = "Reference Model" order = -10 icon = "code-fork" color = "orange" def process(self, name, namespace, context, data): - with maya.maintained_selection(): - nodes = cmds.file( - self.fname, - namespace=namespace, - reference=True, - returnNewNodes=True, - groupReference=True, - groupName="{}:{}".format(namespace, name) - ) + # Create a readable namespace + # Namespace should contain asset name and counter + # TEST_001{_descriptor} where `descriptor` can be `_abc` for example + assetname = "{}_".format(namespace.split("_")[0]) + namespace = avalon.maya.unique_namespace(assetname, format="%03d") + + with avalon.maya.maintained_selection(): + nodes = cmds.file(self.fname, + namespace=namespace, + reference=True, + returnNewNodes=True, + groupReference=True, + groupName="{}:{}".format(namespace, name)) self[:] = nodes @@ -54,15 +58,13 @@ class ModelGPUCacheLoader(api.Loader): cmds.loadPlugin("gpuCache", quiet=True) # Create transform with shape - transform = cmds.createNode("transform", - name=name) - cache = cmds.createNode("gpuCache", - parent=transform, - name="{0}Shape".format(name)) + node_name = "{0}Shape".format(name) + transform = cmds.createNode("transform", name=name) + cache = cmds.createNode("gpuCache", parent=transform, name=node_name) # Set the cache filepath - cmds.setAttr(cache + '.cacheFileName', path, type="string") - cmds.setAttr(cache + '.cacheGeomPath', "|", type="string") # root + cmds.setAttr('{}.cacheFileName'.format(cache), path, type="string") + cmds.setAttr('{}.cacheGeomPath'.format(cache), "|", type="string") # root # Select the transform cmds.select(transform, r=1) diff --git a/colorbleed/plugins/maya/load/load_rig.py b/colorbleed/plugins/maya/load/load_rig.py index 5604ec22c5..0dffefd84b 100644 --- a/colorbleed/plugins/maya/load/load_rig.py +++ b/colorbleed/plugins/maya/load/load_rig.py @@ -22,6 +22,7 @@ class RigLoader(api.Loader): def process(self, name, namespace, context, data): + assert "_" in name, "Naming convention not followed" assetname = "{}_".format(context["asset"]["name"]) unique_namespace = maya.unique_namespace(assetname, format="%03d") nodes = cmds.file(self.fname,