def process(self, instance): import os from maya import cmds from avalon import maya dirname = tempfile.mkdtemp() filename = "{name}.ma".format(**instance.data) path = os.path.join(dirname, filename) # Perform extraction self.log.info("Performing extraction..") with maya.maintained_selection(), maya.without_extension(): self.log.info("Extracting %s" % str(list(instance))) cmds.select(instance, noExpand=True) cmds.file(path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {path}".format(**locals()))
def process(self, instance): import os import ava from maya import cmds from avalon import maya self.log.debug("Loading plug-in..") cmds.loadPlugin("atomImportExport.mll", quiet=True) self.log.info("Extracting curves..") dirname = ava.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass filename = "{name}.curves".format(**instance.data) options = ";".join([ "precision=8", "statics=1", "baked=1", "sdk=0", "constraint=0", "animLayers=0", "selected=selectedOnly", "whichRange=1", "range=1:10", "hierarchy=none", "controlPoints=0", "useChannelBox=1", "options=keys", ("copyKeyCmd=" "-animation objects " "-option keys " "-hierarchy none " "-controlPoints 0 ") ]) controls = next( (node for node in instance if node.endswith("controls_SET")), None) if controls is None: # Backwards compatibility self.log.warning("%s is missing a controls_SET" % instance.name) return with maya.maintained_selection(), maya.without_extension(): cmds.select(controls, noExpand=False) cmds.file(os.path.join(dirname, filename).replace("\\", "/"), force=True, options=options, typ="atomExport", exportSelected=True) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {dirname}".format(**locals()))
def process(self, instance): import os import ava from maya import cmds from avalon import maya self.log.info("Extracting history..") dirname = ava.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass filename = "{name}.history".format(**instance.data) options = ";".join([ "precision=8", "statics=1", "baked=1", "sdk=0", "constraint=0", "animLayers=0", "selected=selectedOnly", "whichRange=1", "range=1:10", "hierarchy=none", "controlPoints=0", "useChannelBox=1", "options=keys", ("copyKeyCmd=" "-animation objects " "-option keys " "-hierarchy none " "-controlPoints 0 ") ]) with maya.maintained_selection(), maya.without_extension(): cmds.select(instance, noExpand=True) cmds.exportEdits( os.path.join(dirname, filename).replace("\\", "/"), force=True, type="editMA", selected=True, includeNetwork=True, includeAnimation=True, includeSetAttrs=True, ) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {dirname}".format(**locals()))
def process(self, instance): import os import polly from maya import cmds from avalon import maya dirname = polly.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass filename = "{name}.ma".format(**instance.data) path = os.path.join(dirname, filename) # Perform extraction self.log.info("Performing extraction..") with maya.maintained_selection(), maya.without_extension(): self.log.info("Extracting %s" % str(list(instance))) cmds.select(instance, noExpand=True) cmds.file( path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False, # Shader assignment is the responsibility of # riggers, for animators, and lookdev, for rendering. shader=False, # Construction history inherited from collection # This enables a selective export of nodes relevant # to this particular plug-in. constructionHistory=False) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {path}".format(**locals()))
def process(self, instance): import os import polly from maya import cmds from avalon import maya dirname = polly.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass filename = "{name}.ma".format(**instance.data) path = os.path.join(dirname, filename) # Perform extraction self.log.info("Performing extraction..") with maya.maintained_selection(), maya.without_extension(): cmds.select(instance, noExpand=True) cmds.file(path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False, constructionHistory=True) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {path}".format(**locals()))
def process(self, instance): import os import ava import contextlib from maya import cmds from avalon import maya @contextlib.contextmanager def sliced_connections(): connections = list() try: # Slice connection from A -/> B for input_ in cmds.sets("in_SET", query=True) or list(): shape = cmds.listRelatives(input_, shapes=True)[0] dst = shape + ".inMesh" for src in cmds.listConnections(dst, plugs=True) or list(): pair = src, dst cmds.disconnectAttr(*pair) connections.append(pair) yield finally: # Restore connection for src, dst in connections: cmds.connectAttr(src, dst, force=True) dirname = ava.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass self.log.info("Extracting lookdev..") filename = "{name}.ma".format(**instance.data) path = os.path.join(dirname, filename) with (sliced_connections(), maya.maintained_selection(), maya.without_extension()): # Export cmds.select(instance, noExpand=True) cmds.file( path, force=True, type="mayaAscii", exportSelected=True, preserveReferences=False, constructionHistory=True, ) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {path}".format(**locals()))
def process(self, instance): import os import json import ava from maya import cmds from avalon import maya from ava.maya import lib dirname = ava.format_staging_dir( root=instance.context.data["workspaceDir"], time=instance.context.data["time"], name=instance.data["name"]) try: os.makedirs(dirname) except OSError: pass filename = "{name}.json".format(**instance.data) path = os.path.join(dirname, filename) self.log.info("Serialising shaders..") relationships = lib.serialise_shaders(instance) self.log.info("Extracting serialisation..") with open(path, "w") as f: json.dump( relationships, f, # This makes the output human-readable, # by padding lines to look visually pleasing. indent=4 ) # Store reference for integration if "files" not in instance.data: instance.data["files"] = list() instance.data["files"].append(filename) # Write individual shaders # TODO(marcus): How about exporting 1 scene, and # maintaining a reference to the shader node name, # as opposed to the file? self.log.info("Extracting shaders..") filename = "{name}.ma".format(**instance.data) path = os.path.join(dirname, filename) with maya.maintained_selection(), maya.without_extension(): cmds.select(relationships.keys(), replace=True, noExpand=True) cmds.file(path, force=True, options="v=0;", type="mayaAscii", preserveReferences=False, exportSelected=True, constructionHistory=False) instance.data["files"].append(filename) instance.data["stagingDir"] = dirname self.log.info("Extracted {instance} to {path}".format(**locals()))