diff --git a/colorbleed/plugins/maya/load/load_setdress_rebuild.py b/colorbleed/plugins/maya/load/load_setdress_rebuild.py index 00544bf938..b616d42893 100644 --- a/colorbleed/plugins/maya/load/load_setdress_rebuild.py +++ b/colorbleed/plugins/maya/load/load_setdress_rebuild.py @@ -1,5 +1,9 @@ +import site + from avalon import api +site.addsitedir(r"C:\Users\User\Documents\development\research\setdress") + class SetDressRebuild(api.Loader): @@ -13,54 +17,16 @@ class SetDressRebuild(api.Loader): def process(self, name, namespace, context, data): - import json from maya import cmds - from avalon.tools.cbloader import lib - from colorbleed.maya import lib as clib - from cb.utils.maya import core + import avalon.maya as amaya - with open(self.fname, "r") as fp: - build_data = json.load(fp) + context_ns = context["subset"]["name"] + with amaya.maintained_selection(): + file_nodes = cmds.file(self.fname, + namespace=context_ns, + reference=True, + returnNewNodes=True, + groupReference=True, + groupName="{}:{}".format(context_ns, name)) - cmds.namespace(add=namespace) - - new_transforms = [] - for representation_id, instances in build_data.items(): - - # Find the corresponding loader - loaders = list(lib.iter_loaders(representation_id)) - - # Ensure context can be passed on - for inst in instances: - # Get the used loader - Loader = next((x for x in loaders if - x.__name__ == inst['loader']), - None) - - if Loader is None: - self.log.warning("Loader is missing: %s. Skipping %s", - inst['loader'], inst) - continue - - # Run the loader - instance_ns = ":".join([namespace, - inst['namespace'].strip(":")]) - container = lib.run_loader(Loader, - representation_id, - namespace=instance_ns) - - container_data = {"objectName": container} - transforms = clib.get_container_transforms(container_data) - # Force sort order, similar to collector - transforms = sorted(transforms) - - for idx, matrix in inst["matrix"].items(): - cmds.xform(transforms[int(idx)], matrix=matrix) - - # Store the created container - self.append(container) - new_transforms.extend(transforms) - - roots = core.getHighestInHierarchy(new_transforms) - cmds.group(roots, name="{}:{}".format(namespace, - context['subset']['name'])) + self[:] = file_nodes