Skip to content

collect_tycache_attributes

CollectTyFlowData

Bases: InstancePlugin, AYONPyblishPluginMixin

Collect Channel Attributes for TyCache Export

Source code in client/ayon_max/plugins/publish/collect_tycache_attributes.py
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
class CollectTyFlowData(pyblish.api.InstancePlugin,
                        AYONPyblishPluginMixin):
    """Collect Channel Attributes for TyCache Export"""

    order = pyblish.api.CollectorOrder - 0.49
    label = "Collect tyCache attribute Data"
    hosts = ['max']
    families = ["tyflow"]
    validate_tycache_frame_range = True

    @classmethod
    def apply_settings(cls, project_settings):

        settings = (
            project_settings["max"]["publish"]["ValidateTyCacheFrameRange"]
        )
        cls.validate_tycache_frame_range = settings["active"]

    def process(self, instance):
        context = instance.context
        container_name = instance.data["instance_node"]
        container = rt.GetNodeByName(container_name)
        tyc_product_names = [
            name for name
            in container.modifiers[0].AYONTyCacheData.tyc_exports
        ]
        attr_values = self.get_attr_values_from_data(instance.data)

        i_product_type = instance.data["productType"]
        if i_product_type == instance.data["productBaseType"]:
            i_product_type = None

        for tyc_product_name in tyc_product_names:
            self.log.debug(f"Creating instance for operator:{tyc_product_name}")
            # Replace all runs of whitespace with underscore
            prod_name = re.sub(r"\s+", "_", tyc_product_name)
            operator = next((node for node in get_tyflow_export_operators()
                             if node.name == tyc_product_name), None)   # noqa
            if operator is None:
                self.log.warning(
                    f"No matching export operator found for "
                    f"{tyc_product_name}. Skipping instance creation."
                )
                continue

            tyc_instance = context.create_instance(tyc_product_name)
            tyc_instance[:] = instance[:]
            tyc_instance.data.update(copy.deepcopy(dict(instance.data)))

            product_base_type = (
                "tycache"
                if operator.exportMode == 2
                else "tyspline"
            )
            # Keep custom product type only if is not the same
            #   as product base type
            product_type = i_product_type
            if not product_type:
                product_type = product_base_type

            tyc_instance.data.update({
                "name": f"{container_name}_{prod_name}",
                "label": f"{container_name}_{prod_name}",
                "family": product_base_type,
                "families": [product_base_type],
                "productName": f"{container_name}_{prod_name}",
                # get the name of operator for the export
                "operator": operator,
                "exportMode": operator.exportMode,
                "material_cache": attr_values.get("material"),
                "productType": product_type,
                "productBaseType": product_base_type,
                "creator_identifier": (
                    f"io.ayon.creators.max.{product_base_type}"),
                "publish_attributes": {
                    "ValidateTyCacheFrameRange": {
                        "active": attr_values.get("has_frame_range_validator")}
                }
            })
            instance.append(tyc_instance)

    @classmethod
    def get_attribute_defs(cls):
        return [
            BoolDef("has_frame_range_validator",
                    label="Validate TyCache Frame Range",
                    default=cls.validate_tycache_frame_range),
            BoolDef("material",
                    label="Publish along with Material",
                    default=True)
        ]