Skip to content

pre_launch_workfile

Pre-launch hook for Marvelous Designer workfile handling.

This module provides a hook that creates a temporary Zprj file for MD when no last workfile exists or when not starting from the last workfile.

CreateTempZprjFile

Bases: PreLaunchHook

Create Temp Zprj File to Marvelous Designer.

The temp zprj file would be created in Marvelous Designer prior to the launch of the software if there is no last workfile

Hook GlobalHostDataHook must be executed before this hook.

Source code in client/ayon_marvelousdesigner/hooks/pre_launch_workfile.py
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
class CreateTempZprjFile(PreLaunchHook):
    """Create Temp Zprj File to Marvelous Designer.

    The temp zprj file would be created in Marvelous Designer prior to
    the launch of the software if there is no last workfile

    Hook `GlobalHostDataHook` must be executed before this hook.
    """
    app_groups: ClassVar = {"marvelousdesigner"}
    order = 12
    launch_types: ClassVar = {LaunchTypes.local}

    def execute(self) -> None:
        """Execute the pre-launch hook to create temp zprj file."""
        workfile_path = self.get_workfile_path()

        self.launch_context.launch_args.append(workfile_path)

    def get_workfile_path(self) -> str:
        workfile_path = self.data.get("workfile_path")
        if workfile_path:
            return workfile_path

        if self.data.get("start_last_workfile"):
            self.log.info("It is set to start last workfile on start.")
            last_workfile = self.data.get("last_workfile_path")
            if last_workfile and os.path.exists(last_workfile):
                return last_workfile

        source_template_file = os.path.join(
            MARVELOUS_DESIGNER_HOST_DIR, "default_zprj", "Untitled_MD.zprj"
        )
        staging_dir = tempdir.get_temp_dir(
            self.data["project_name"],
            use_local_temp=True
        )
        spm_filename = os.path.basename(source_template_file)
        workfile_path = os.path.join(staging_dir, spm_filename)
        shutil.copyfile(source_template_file, workfile_path)
        self.launch_context.env["AYON_TEMP_DIR"] = staging_dir
        return workfile_path

execute()

Execute the pre-launch hook to create temp zprj file.

Source code in client/ayon_marvelousdesigner/hooks/pre_launch_workfile.py
28
29
30
31
32
def execute(self) -> None:
    """Execute the pre-launch hook to create temp zprj file."""
    workfile_path = self.get_workfile_path()

    self.launch_context.launch_args.append(workfile_path)