def process(self, context): from maya import cmds if not os.environ["TASK"] == "rigging": return self.log.info("No rig found") name = os.environ["ITEM"] # Get the root transform self.log.info("Rig found: %s" % name) assembly = "|{name}_GRP".format(name=name) assert cmds.objExists(assembly), ( "Rig did not have an appropriate assembly: %s" % assembly) self.log.info("Capturing instance contents: %s" % assembly) instance = context.create_instance(name=name, family="rig") with pyblish_maya.maintained_selection(): cmds.select(assembly) instance[:] = cmds.file(exportSelected=True, preview=True, constructionHistory=True, force=True) # Add rig-specific object sets for objset in ("controls_SET", "pointcache_SET"): if cmds.objExists(objset): instance.add(objset) instance.set_data("preserveReferences", False) self.log.info("Successfully collected %s" % name)
def process(self, instance): # Define extract output file path dir_path = pyblish_utils.temp_dir(instance) filename = "{0}.ma".format(instance.name) path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction..") with pyblish_maya.maintained_selection(): pymel.core.select(instance) # cmds.select(instance, noExpand=True) pymel.core.system.exportSelected( path, constructionHistory=False, preserveReferences=False, shader=False, channels=False, constraints=False, force=True, type="mayaAscii", ) instance.data["outputPath_ma"] = path self.log.info("Extracted instance '{0}' to: {1}".format(instance.name, path))
def process(self, instance): node = instance.data['rig'] versionDir = instance.data['vprefix'] + instance.data['version'] publishDir = os.path.join(instance.data['publishDir'], versionDir) if not os.path.exists(publishDir): os.makedirs(publishDir) metadata = instance.data['metadata'] metadata['version'] = versionDir task = ftrack.Task(instance.context.data['taskid']) assetName = task.getParent().getName().lower() assetFile = os.path.join(publishDir, '%s_rig.mb' % assetName) refFile = os.path.join(instance.data['publishDir'], '%s_rig.mb' % assetName) metadata['publish_rig'] = refFile with maintained_selection(): cmds.select(node, noExpand=True) cmds.file(assetFile, force=True, typ='mayaBinary', exportSelected=True, preserveReferences=False, constructionHistory=True) if os.path.exists(refFile): os.remove(refFile) os.symlink(assetFile, refFile) self.log.info('Extraction completed successfully')
def process(self, instance): # Define extract output file path dir_path = pyblish_utils.temp_dir(instance) filename = instance.name path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction") with pyblish_maya.maintained_selection(): self.log.debug("instance: " + str(instance)) mc.select(instance) # cmds.select(instance, noExpand=True) # self.log.info(instance.data['preserveReferences']) # preserveReferences = instance.data['preserveReferences'] or 'False' path = mc.file(path, es=True, constructionHistory=False, preserveReferences=False, shader=True, channels=False, constraints=False, force=True, type='mayaAscii') instance.data['outputPath_ma'] = path self.log.info("Extracted instance '{0}' to: {1}".format( instance.name, path))
def process(self, instance): # Define extract output file path dir_path = pyblish_utils.temp_dir(instance) filename = instance.name path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction..") with pyblish_maya.maintained_selection(): roots = instance.data.get('roots') if not roots: roots = instance mc.select(roots) # cmds.select(instance, noExpand=True) path = mc.file(path, es=True, constructionHistory=False, preserveReferences=False, shader=False, channels=False, constraints=False, force=True, type='OBJexport') instance.data['outputPath_obj'] = path self.log.info("Extracted instance '{0}' to: {1}".format( instance.name, path))
def repair(cls, instance): """Repair the meshes by 'baking' offsets into the input mesh""" invalid = cls.get_invalid(instance) # TODO: Find a better way to reset values whilst preserving offsets with pyblish_maya.maintained_selection(): for mesh in invalid: cmds.polyMoveVertex(mesh, constructionHistory=False)
def repair(self, instance): """Repair the meshes by 'baking' offsets into the input mesh""" meshes = cmds.ls(instance, type='mesh', dag=True, long=True) invalid = [mesh for mesh in meshes if self.is_invalid(mesh)] # TODO: Find a better way to reset values whilst preserving offsets with pyblish_maya.maintained_selection(): for mesh in invalid: cmds.polyMoveVertex(mesh, constructionHistory=False)
def process(self, context): from maya import cmds schema = pyblish_magenta.schema.load() tester = schema.get_template("test_asset") fpath = cmds.file(query=True, expandName=True) fpath.replace("\\", "/") holders = tester.parse(fpath) model_name = holders['asset'].split('.')[0] if "modeling" not in os.environ["TASK"].split(','): return self.log.info("No model found") if 'genre' not in holders: self.log.info("No genre found") elif "model" not in holders['genre']: self.log.info("Asset's genre not modeling") name = model_name # holders['container'] os.environ['ITEM'] = holders['container'] # Get the root transform self.log.info("Model found: %s" % name) pattern = ProjectEnv.get_config(self.config_key)['root_node_name_pattern'] assembly = pattern.format(name=name) assert cmds.objExists(assembly), ( "Model did not have an appropriate assembly: %s" % assembly) self.log.info("Capturing instance contents: %s" % assembly) with pyblish_maya.maintained_selection(): cmds.select(assembly) nodes = cmds.file(exportSelected=True, preview=True, constructionHistory=False, force=True, shader=False, channels=False, expressions=False, constraints=False) nodes = cmds.ls(nodes, long=True) self.log.info("Reducing nodes to shapes only") shapes = cmds.ls(nodes, noIntermediate=True, exactType="mesh", long=True, dag=True) assert shapes, "Model did not have any shapes" instance = context.create_instance(name=name, family="model") instance[:] = nodes self.log.info("Successfully collected %s" % name)
def process(self, instance): import os from maya import cmds from mindbender import api from pyblish_maya import maintained_selection dirname = api.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 maintained_selection(): 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): from maya import cmds temp_dir = self.temp_dir(instance) temp_file = os.path.join(temp_dir, instance.data("name")) with pyblish_maya.maintained_selection(): cmds.select(instance, noExpand=True) self.log.info("Extracting \"%s\" into %s" % ( cmds.ls(selection=True), temp_file)) cmds.file(temp_file, force=True, exportSelected=True, constructionHistory=True, type="mayaAscii", preserveReferences=False)
def process(self, instance): from maya import cmds # Define extract output file path dir_path = self.temp_dir(instance) filename = "{0}.ma".format(instance.name) path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction..") # Get only the shape contents we need in such a way that we avoid # taking along intermediateObjects members = instance.data("setMembers") members = cmds.ls(members, dag=True, shapes=True, type=("mesh", "nurbsCurve"), noIntermediate=True, long=True) from cb.utils.maya import context with context.no_display_layers(instance): with context.displaySmoothness(members, divisionsU=0, divisionsV=0, pointsWire=4, pointsShaded=1, polygonObject=1): with context.shader(members, shadingEngine="initialShadingGroup"): with pyblish_maya.maintained_selection(): cmds.select(members, noExpand=True) cmds.file(path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False, channels=False, constraints=False, expressions=False, constructionHistory=False) self.log.info("Extracted instance '{0}' to: {1}".format( instance.name, path))
def process(self, instance): import os import pyblish_maya import pymel # Skip any remote instances if "remote" in instance.data["families"]: return # Export to file. path = instance.data["output_path"] if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) with pyblish_maya.maintained_selection(): # Disconnect animation if requested connections = [] if instance.data.get("disconnectAnimation", False): # Disconnect connections to anim curves, and store for later for node in pymel.core.ls(type="transform"): connections.extend(self.disconnect(node, "animCurveTA")) connections.extend(self.disconnect(node, "animCurveTU")) connections.extend(self.disconnect(node, "animCurveTL")) # Export selection pymel.core.select(instance.data["nodes"], noExpand=True) export_type = set(self.families) & set(instance.data["families"]) pymel.core.system.exportSelected( path, force=True, type=list(export_type)[0], preserveReferences=False, constructionHistory=instance.data.get( "constructionHistory", True ) ) # Reconnect animation for connection in connections: connection["source"] >> connection["destination"]
def process(self, instance): publish_path = instance.data['publishFile'] if not os.path.exists(os.path.dirname(publish_path)): os.makedirs(os.path.dirname(publish_path)) for f in instance.data['textures']: if os.path.isfile(f): new_tex = os.path.join(os.path.dirname(publish_path), os.path.basename(f)) output = shutil.copy(f, new_tex) with pyblish_maya.maintained_selection(): self.log.debug("instance: " + str(instance)) cmds.select(instance) # preserveReferences = instance.data['preserveReferences'] or 'False' scene_name = os.path.basename(instance.context.data['currentFile']) dir_path = pyblish_utils.temp_dir(instance) new_scene = os.path.join(dir_path, scene_name) new_scene = os.path.join(new_scene).replace('\\', '/') self.log.debug('pack extraction path: {}'.format(new_scene)) # new_scene = os.path.join(new_path, os.path.basename(instance.context.data['currentFile'])) path = cmds.file(new_scene, es=True, constructionHistory=False, preserveReferences=False, shader=True, channels=False, constraints=False, force=True, type='mayaBinary') instance.data['outputPath'] = path script_path = r"K:\.core\dev\pyblish\pyblish-kredenc\pyblish_kredenc\utils\change_texture_fbx.py" command = r"mayapy {} {} {} & pause".format(script_path, new_scene, publish_path) subprocess.Popen(command)
def process(self, instance): import os import pyblish_maya import pymel # Skip any remote instances if "remote" in instance.data["families"]: return # Export to file. path = instance.data["output_path"] if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) with pyblish_maya.maintained_selection(): # Disconnect animation if requested connections = [] if instance.data.get("disconnectAnimation", False): # Disconnect connections to anim curves, and store for later for node in pymel.core.ls(type="transform"): connections.extend(self.disconnect(node, "animCurveTA")) connections.extend(self.disconnect(node, "animCurveTU")) connections.extend(self.disconnect(node, "animCurveTL")) # Export selection pymel.core.select(instance.data["nodes"], noExpand=True) export_type = set(self.families) & set(instance.data["families"]) pymel.core.system.exportSelected( path, force=True, type=list(export_type)[0], preserveReferences=False, constructionHistory=instance.data.get("constructionHistory", True)) # Reconnect animation for connection in connections: connection["source"] >> connection["destination"]
def process(self, instance): # Ensure alembic exporter is loaded cmds.loadPlugin('AbcExport', quiet=True) # Define extract output file path temp_dir = self.temp_dir(instance) # parent_dir = os.path.join(temp_dir, instance.data("name")) parent_dir = temp_dir filename = "{0}.abc".format(instance.name) path = os.path.join(parent_dir, filename) # Alembic Exporter requires forward slashes path = path.replace('\\', '/') self.log.info("Extracting alembic to: {0}".format(path)) options = self.default_options options["userAttr"] = ("uuid",) options = self.parse_overrides(instance, options) job_str = self.parse_options(options) job_str += ' -file "{0}"'.format(path) self.log.info("Extracting alembic to: {0}".format(path)) verbose = instance.data('verbose', False) if verbose: self.log.debug('Alembic job string: "{0}"'.format(job_str)) if not os.path.exists(parent_dir): os.makedirs(parent_dir) with suspension(): with pyblish_maya.maintained_selection(): self.log.debug( "Preparing %s for export using the following options: %s\n" "and the following string: %s" % (list(instance), json.dumps(options, indent=4), job_str)) cmds.select(instance, hierarchy=True) cmds.AbcExport(j=job_str, verbose=verbose)
def process(self, instance): from maya import cmds # Define extract output file path dir_path = self.temp_dir(instance) filename = "{0}.ma".format(instance.name) path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction..") with pyblish_maya.maintained_selection(): cmds.select(instance, noExpand=True) cmds.file(path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False, constructionHistory=False) self.log.info("Extracted instance '{0}' to: {1}".format( instance.name, path))
def process(self, instance): from maya import cmds # Define extract output file path dir_path = self.temp_dir(instance) filename = "{0}.ma".format(instance.name) path = os.path.join(dir_path, filename) # Perform extraction self.log.info("Performing extraction..") with pyblish_maya.maintained_selection(): cmds.select(instance, noExpand=True) cmds.file(path, force=True, typ="mayaAscii", exportSelected=True, preserveReferences=False, constructionHistory=True) self.log.info("Extracted instance '{0}' to: {1}".format( instance.name, path))
def process(self, instance): import os from maya import cmds from mindbender import api from pyblish_maya import maintained_selection dirname = api.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 maintained_selection(): 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): # Ensure alembic exporter is loaded cmds.loadPlugin('AbcExport', quiet=True) # Define extract output file path temp_dir = self.temp_dir(instance) # parent_dir = os.path.join(temp_dir, instance.data("name")) parent_dir = temp_dir filename = "{0}.abc".format(instance.name) path = os.path.join(parent_dir, filename) # Alembic Exporter requires forward slashes path = path.replace('\\', '/') options = self.default_options options["userAttr"] = ("uuid", ) options = self.parse_overrides(instance, options) job_str = self.parse_options(options) job_str += ' -file "{0}"'.format(path) self.log.info("Extracting alembic to: {0}".format(path)) verbose = instance.data('verbose', False) if verbose: self.log.debug('Alembic job string: "{0}"'.format(job_str)) if not os.path.exists(parent_dir): os.makedirs(parent_dir) with suspension(): with pyblish_maya.maintained_selection(): self.log.debug( "Preparing %s for export using the following options: %s\n" "and the following string: %s" % (list(instance), json.dumps(options, indent=4), job_str)) cmds.select(instance.data("setMembers"), hierarchy=True) cmds.AbcExport(j=job_str, verbose=verbose)
def process(self, context): from maya import cmds if not os.environ["TASK"] == "modeling": return self.log.info("No model found") name = os.environ["ITEM"] # Get the root transform self.log.info("Model found: %s" % name) assembly = "|%s_GRP" % name assert cmds.objExists(assembly), "Model did not have an appropriate assembly: %s" % assembly self.log.info("Capturing instance contents: %s" % assembly) with pyblish_maya.maintained_selection(): cmds.select(assembly) nodes = cmds.file( exportSelected=True, preview=True, constructionHistory=False, force=True, shader=False, channels=False, expressions=False, constraints=False, ) nodes = cmds.ls(nodes, long=True) self.log.info("Reducing nodes to shapes only") shapes = cmds.ls(nodes, noIntermediate=True, exactType="mesh", long=True, dag=True) assert shapes, "Model did not have any shapes" instance = context.create_instance(name=name, family="model") instance[:] = nodes self.log.info("Successfully collected %s" % name)
def process(self, instance): import os import json from mindbender import api from mindbender.maya import lib from pyblish_maya import maintained_selection from maya import cmds dirname = api.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 maintained_selection(): 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()))
def process(self, instance): import os import contextlib from mindbender import api from pyblish_maya import maintained_selection from maya import cmds @contextlib.contextmanager def sliced_connections(): connections = list() try: # Slice connection from A -/> B for input_ in cmds.sets("in_SET", query=True): shape = cmds.listRelatives(input_, shapes=True)[0] dst = shape + ".inMesh" for src in cmds.listConnections(dst, plugs=True): 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 = api.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 contextlib.nested(sliced_connections(), maintained_selection()): # 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()))