def get_invalid(cls, instance): from maya import cmds from avalon.pipeline import AVALON_CONTAINER_ID from reveries.maya import lib invalid = list() camera = instance.data["camera"] # Is camera being containerized ? containers = lib.lsAttr("id", AVALON_CONTAINER_ID) transform = cmds.listRelatives(camera, parent=True, fullPath=True)[0] for set_ in cmds.listSets(object=transform) or []: if set_ in containers: break else: # Is camera being publish ? camera_ln = cmds.ls(camera, long=True)[0] camera_instances = [ i for i in instance.context if (i.data["family"] == cls.camera_family and i.data.get("publish", True)) ] if not any(camera_ln in inst for inst in camera_instances): invalid.append(camera) return invalid
def get_invalid(cls, instance): from reveries.maya import lib from maya import cmds containers = lib.lsAttr("id", AVALON_CONTAINER_ID) cameras = set(instance.data["renderCam"]) has_versioned = set() # Is camera being containerized ? for cam in cameras: transform = cmds.listRelatives(cam, parent=True, fullPath=True)[0] for set_ in cmds.listSets(object=transform) or []: if set_ in containers: has_versioned.add(cam) break # Is camera being publish ? not_containerized = cameras - has_versioned camera_instances = [ i for i in instance.context if (i.data["family"] == cls.camera_family and i.data.get("publish", True)) ] for cam in not_containerized: for inst in camera_instances: if cam in inst: has_versioned.add(cam) break return list(cameras - has_versioned)
def get_invalid(cls, instance): from reveries.maya import lib from maya import cmds containers = lib.lsAttr("id", AVALON_CONTAINER_ID) surfaces = cmds.ls(instance, type="surfaceShape", noIntermediate=True, long=True) # Check on transform node transforms = set( cmds.listRelatives(surfaces, parent=True, fullPath=True) or []) has_versioned = set() # Is node being containerized ? for node in transforms: for set_ in cmds.listSets(object=node) or []: if set_ in containers: has_versioned.add(node) break not_containerized = transforms - has_versioned other_instances = [ i for i in instance.context if (i.data["family"] not in cls.families and i.data.get("publish", True)) ] # Is node being publish ? for node in not_containerized: for inst in other_instances: if node in inst: has_versioned.add(node) break # Or hidden ? start = instance.data["startFrame"] end = instance.data["endFrame"] step = instance.data["byFrameStep"] not_versioned_visible = set() not_versioned = transforms - has_versioned for node in not_versioned: frame = start while frame < end: if lib.is_visible(node, time=frame): not_versioned_visible.add(node) break frame += step return list(not_versioned_visible)
def _publish(self, rig_source, rig_subsets): import os import re import pyblish.util import maya.cmds as cmds from avalon import api from reveries.maya import lib # Switch task api.update_current_task(task="rigging", asset=self.asset_name) # Open rig source file cmds.file(rig_source, open=True, force=True) # Update all loaded model which subset name has matched _updated = False host = api.registered_host() for _container in host.ls(): if _container["name"] == self.model_subset: api.update(_container) _updated = True if not _updated: # Not likely to happen, but just in case raise Exception("No matched model subset, this is a bug.") # Config rig instances' activities # Activate rig instances that need to be published, and deactivate # the rest. for instance_set in lib.lsAttr("id", "pyblish.avalon.instance"): active = cmds.getAttr(instance_set + ".subset") in rig_subsets cmds.setAttr(instance_set + ".active", active) # Save as file _tmp_dir = os.path.join(os.path.dirname(rig_source), "_auto_update") if not os.path.exists(_tmp_dir): os.mkdir(_tmp_dir) os.chmod(_tmp_dir, 777) # Compose a good file name basename, ext = os.path.splitext(os.path.basename(rig_source)) if "auto_model_update" not in basename: _new_fname = "{}.auto_model_update.001{}".format(basename, ext) else: current_v = re.findall(".auto_model_update.(\\d+).", rig_source)[0] new_v = "{:03d}".format(int(current_v) + 1) _new_fname = "{}{}".format(basename, ext) _new_fname = _new_fname.replace(".{}.published.".format(current_v), ".{}.".format(new_v)) _save_to = os.path.join(_tmp_dir, _new_fname) cmds.file(rename=_save_to) cmds.file(force=True, save=True) print("Saved to : {}".format(_save_to)) # Publish pyblish.api.register_target("localhost") # Fix AvalonUUID before validate ValidateAvalonUUID = next(p for p in pyblish.api.discover() if p.__name__ == "ValidateAvalonUUID") for instance in pyblish.util.collect(): try: ValidateAvalonUUID.fix_invalid_missing(instance) except Exception as e: print("Fix uuid failed: {}.".format(e)) context = pyblish.util.collect() context.data["comment"] = "Auto update model to latest version." context = pyblish.util.validate(context=context) context = pyblish.util.extract(context=context) if not all(result["success"] for result in context.data["results"]): raise RuntimeError("Atomicity not held, aborting.") # Will run integration later.. self.contexts.append(context)