Skip to content

load_workfile

WorkfileLoader

Bases: LoaderPlugin

SpeedTree Workfile Loader.

Source code in client/ayon_speedtree/plugins/load/load_workfile.py
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
class WorkfileLoader(load.LoaderPlugin):
    """SpeedTree Workfile Loader."""

    product_types = {"workfile"}
    representations = {"spm"}
    order = -9
    icon = "code-fork"
    color = "white"
    label = "Load Workfile"

    def load(self, context, name=None, namespace=None, data=None):
        file_path = os.path.normpath(
            self.filepath_from_context(context)
        )
        if not os.path.exists(file_path):
            raise FileExistsError("The loaded file not found.")


        host = registered_host()
        work_context = get_current_workfile_context()
        project_name = work_context.get("project_name")
        folder_path = work_context.get("folder_path")
        task_name = work_context.get("task_name")

        if not folder_path:
            current_context = get_current_context()
            project_name = current_context.get("project_name")
            folder_path = current_context.get("folder_path")
            task_name = current_context.get("task_name")

        host_name = "speedtree"
        template_key = get_workfile_template_key_from_context(
            project_name,
            folder_path,
            task_name,
            host_name,
        )
        anatomy = Anatomy(project_name)

        data = get_template_data_with_names(
            project_name, folder_path, task_name, host_name
        )

        data["root"] = anatomy.roots

        work_template = anatomy.get_template_item("work", template_key)

        extensions = host.get_workfile_extensions()
        extension = extensions[0]
        data["ext"] = extension.lstrip(".")

        work_root = work_template["directory"].format_strict(data)
        version = get_last_workfile_with_version(
            work_root, work_template["file"].template, data, extensions
        )[1]

        if version is None:
            version = get_versioning_start(
                project_name,
                "tvpaint",
                task_name=task_name,
                task_type=data["task"]["type"],
                product_type="workfile"
            )
        else:
            version += 1

        data["version"] = version

        filename = work_template["file"].format_strict(data)
        path = os.path.join(work_root, filename)
        os.environ["CURRENT_SPM"] = file_path
        host.save_workfile(path)