Skip to content

extract_workfile

SilhouetteExtractWorkfile

Bases: Extractor

Source code in client/ayon_silhouette/plugins/publish/extract_workfile.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
class SilhouetteExtractWorkfile(publish.Extractor):
    label = "Extract Workfile"
    hosts = ["silhouette"]
    families = ["workfile"]

    add_project_sfx = False

    def process(self, instance):
        """Extract the current working file as .zip"""
        # Note that Silhouette project workfiles are actually folders,
        # not files.

        current_file = instance.context.data["currentFile"]
        if not current_file:
            raise publish.PublishError("No current file found in context")

        # Save current file
        host = registered_host()
        host.save_workfile()

        # Zip current workfile (Silhouette workfiles are folders)
        staging_dir = self.staging_dir(instance)
        filename = f"{instance.name}.zip"
        lib.zip_folder(current_file, os.path.join(staging_dir, filename))

        # Add representation
        instance.data.setdefault("representations", []).append({
            "name": "sfx_zip",
            "ext": "zip",
            "files": filename,
            "stagingDir": staging_dir,
        })

        if self.add_project_sfx:
            # Add the project.sfx file as a separate representation
            project_sfx = os.path.join(current_file, "project.sfx")

            instance.data.setdefault("representations", []).append({
                "outputName": "project",
                "name": "sfx_project",
                "ext": "sfx",
                "files": os.path.basename(project_sfx),
                "stagingDir": os.path.dirname(project_sfx),
            })

process(instance)

Extract the current working file as .zip

Source code in client/ayon_silhouette/plugins/publish/extract_workfile.py
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
def process(self, instance):
    """Extract the current working file as .zip"""
    # Note that Silhouette project workfiles are actually folders,
    # not files.

    current_file = instance.context.data["currentFile"]
    if not current_file:
        raise publish.PublishError("No current file found in context")

    # Save current file
    host = registered_host()
    host.save_workfile()

    # Zip current workfile (Silhouette workfiles are folders)
    staging_dir = self.staging_dir(instance)
    filename = f"{instance.name}.zip"
    lib.zip_folder(current_file, os.path.join(staging_dir, filename))

    # Add representation
    instance.data.setdefault("representations", []).append({
        "name": "sfx_zip",
        "ext": "zip",
        "files": filename,
        "stagingDir": staging_dir,
    })

    if self.add_project_sfx:
        # Add the project.sfx file as a separate representation
        project_sfx = os.path.join(current_file, "project.sfx")

        instance.data.setdefault("representations", []).append({
            "outputName": "project",
            "name": "sfx_project",
            "ext": "sfx",
            "files": os.path.basename(project_sfx),
            "stagingDir": os.path.dirname(project_sfx),
        })