Skip to content

extract_tycache

ExtractTyCache

Bases: Extractor

Extract tycache format with tyFlow operators. Notes: - TyCache only works for TyFlow Pro Plugin.

Methods:

Name Description
self._extract_tyflow_particles

sets the necessary attributes and export tyCache with the export particle operator(s)

self.get_files

get the files with tyFlow naming convention before publishing

Source code in client/ayon_max/plugins/publish/extract_tycache.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class ExtractTyCache(publish.Extractor):
    """Extract tycache format with tyFlow operators.
    Notes:
        - TyCache only works for TyFlow Pro Plugin.

    Methods:
        self._extract_tyflow_particles: sets the necessary
            attributes and export tyCache with the export
            particle operator(s)

        self.get_files(): get the files with tyFlow naming convention
            before publishing
    """

    order = pyblish.api.ExtractorOrder - 0.2
    label = "Extract TyCache"
    hosts = ["max"]
    families = ["tycache", "tyspline"]

    def process(self, instance):
        # TODO: let user decide the param
        self.log.debug("Extracting Tycache...")

        stagingdir = self.staging_dir(instance)

        export_mode = instance.data.get("exportMode", 2)
        material_cache = instance.data.get("material_cache")
        operator = instance.data["operator"]
        representations = instance.data.setdefault("representations", [])
        start_frame = instance.data["frameStartHandle"]
        end_frame = instance.data["frameEndHandle"]
        product_name = instance.data.get("productName")
        tyc_fnames = []
        tyc_mesh_fnames = []
        with maintained_selection():
            filename = f"{product_name}.tyc"
            path = os.path.join(stagingdir, filename)
            filenames = self.get_files(
                product_name, start_frame, end_frame)
            self._extract_tyflow_particles(
                operator, path, export_mode, material_cache)
            mesh_filename = f"{product_name}__tyMesh.tyc"
            tyc_fnames.extend(filenames)
            tyc_mesh_fnames.append(mesh_filename)
        representation = {
            "name": "tyc",
            "ext": "tyc",
            "files": (
                tyc_fnames if len(tyc_fnames) > 1
                else tyc_fnames[0]),
            "stagingDir": stagingdir
        }
        representations.append(representation)
        mesh_repres = {
            'name': 'tyMesh',
            'ext': 'tyc',
            'files': (
                tyc_mesh_fnames if len(tyc_mesh_fnames) > 1
                else tyc_mesh_fnames[0]),
            "stagingDir": stagingdir
        }
        representations.append(mesh_repres)
        # Get the material filename of which assigned in
        # tyCache for extraction
        material_filename = f"{product_name}__tyMtl.mat"
        full_material_name = os.path.join(stagingdir, material_filename)
        full_material_name = full_material_name.replace("\\", "/")
        if material_cache and os.path.exists(full_material_name):
            self.log.debug("Extracting material along with tycache.")
            mateiral_repres = {
                "name": 'tyMtl',
                "ext": 'mat',
                'files': material_filename,
                'stagingDir': stagingdir,
                "outputName": '__tyMtl'
            }
            representations.append(mateiral_repres)
        self.log.debug(
            f"Extracted instance '{instance.name}' to: {stagingdir}")

    def get_files(self, product_name, start_frame, end_frame):
        """Get file names for tyFlow in tyCache format.

        Set the filenames accordingly to the tyCache file
        naming extension(.tyc) for the publishing purpose

        Actual File Output from tyFlow in tyCache format:
        <InstanceName>_<operator>__tyPart_<frame>.tyc

        e.g. tycacheMain__tyPart_00000.tyc

        Args:
            product_name (str): product name
            start_frame (int): frame start
            end_frame (int): frame end

        Returns:
            filenames(list): list of filenames

        """
        filenames = []
        for frame in range(int(start_frame), int(end_frame) + 1):
            filename = f"{product_name}__tyPart_{frame:05}.tyc"
            filenames.append(filename)
        return filenames

    def _extract_tyflow_particles(self, operator, filepath,
                                  export_mode, material_cache):
        """Exports tyCache particle with the necessary export settings

        Args:
            operators (list): List of Export Particle operator
            start (int): Start frame.
            end (int): End frame.
            filepath (str): Output path of the TyCache file.
            export_mode (int): Export Mode for the TyCache Output.
            material_cache (bool): Whether tycache should publish
                along with material

        """
        if rt.getProperty(operator, "exportMode") != export_mode:
            return
        export_settings = {
            "tycacheCreateObject": False,
            "tycacheCreateObjectIfNotCreated": False,
            "tycacheChanMaterials": True if material_cache else False,
            "tyCacheFilename": filepath.replace("\\", "/"),
        }

        for key, value in export_settings.items():
            rt.setProperty(operator, key, value)
        # export tyCache
        operator.ExportTyCache()

get_files(product_name, start_frame, end_frame)

Get file names for tyFlow in tyCache format.

Set the filenames accordingly to the tyCache file naming extension(.tyc) for the publishing purpose

Actual File Output from tyFlow in tyCache format: __tyPart.tyc

e.g. tycacheMain__tyPart_00000.tyc

Parameters:

Name Type Description Default
product_name str

product name

required
start_frame int

frame start

required
end_frame int

frame end

required

Returns:

Name Type Description
filenames list

list of filenames

Source code in client/ayon_max/plugins/publish/extract_tycache.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def get_files(self, product_name, start_frame, end_frame):
    """Get file names for tyFlow in tyCache format.

    Set the filenames accordingly to the tyCache file
    naming extension(.tyc) for the publishing purpose

    Actual File Output from tyFlow in tyCache format:
    <InstanceName>_<operator>__tyPart_<frame>.tyc

    e.g. tycacheMain__tyPart_00000.tyc

    Args:
        product_name (str): product name
        start_frame (int): frame start
        end_frame (int): frame end

    Returns:
        filenames(list): list of filenames

    """
    filenames = []
    for frame in range(int(start_frame), int(end_frame) + 1):
        filename = f"{product_name}__tyPart_{frame:05}.tyc"
        filenames.append(filename)
    return filenames