implemented monkey code

This commit is contained in:
aardschok 2017-10-13 17:45:53 +02:00
parent bf289ab75b
commit b40af5d190

View file

@ -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