Bases: PreLaunchHook
Define whether open last workfile should run post initialize.
Source code in client/ayon_maya/hooks/pre_open_workfile_post_initialization.py
6
7
8
9
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 | class MayaPreOpenWorkfilePostInitialization(PreLaunchHook):
"""Define whether open last workfile should run post initialize."""
# Before AddLastWorkfileToLaunchArgs.
order = 9
app_groups = {"maya"}
launch_types = {LaunchTypes.local}
def execute(self):
if not self._should_load_post_maya_init():
return
key = "AYON_MAYA_WORKFILE_PATH"
# Force disable the `AddLastWorkfileToLaunchArgs`.
workfile_path = self.data.pop("workfile_path", None)
start_last_workfile = self.data.pop("start_last_workfile", None)
# Explicit workfile is set to be used
if workfile_path:
self.launch_context.env[key] = workfile_path
return
# Ignore if there's no last workfile to start.
if not start_last_workfile:
return
# Ignore if the last workfile path does not exist, this may be the case
# when starting a context that has no workfiles yet.
last_workfile_path: str = self.data.get("last_workfile_path")
if not last_workfile_path or not os.path.exists(last_workfile_path):
self.log.info("Current context does not have any workfile yet.")
return
self.log.info(
f"Opening workfile post initialization: {last_workfile_path}"
)
self.launch_context.env[key] = last_workfile_path
def _should_load_post_maya_init(self) -> bool:
maya_settings = self.data["project_settings"]["maya"]
# Do nothing if post workfile initialization is disabled.
if maya_settings["open_workfile_post_initialization"]:
self.log.debug(
"Opening workfile post initialization because Open Workfile"
" Post Initialization setting is enabled."
)
return True
# When using explicit plug-in load, we must delay the file open
# to ensure the loading happens the way we need, so we still force it.
if maya_settings["explicit_plugins_loading"]["enabled"]:
self.log.debug(
"Opening workfile post initialization because Explicit Plugins"
" Loading setting is enabled."
)
return True
return False
|