Skip to content

Commit

Permalink
move the check on the mxp_workspace being enabled in project settings…
Browse files Browse the repository at this point in the history
… into the prelaunch hook
  • Loading branch information
moonyuet committed Jul 12, 2024
1 parent 330485f commit a62d69c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
14 changes: 13 additions & 1 deletion client/ayon_max/hooks/pre_copy_mxp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ayon_applications import PreLaunchHook, LaunchTypes
from ayon_max.mxp import create_workspace_mxp
from ayon_core.settings import get_project_settings


class PreCopyMxp(PreLaunchHook):
Expand All @@ -12,9 +13,20 @@ class PreCopyMxp(PreLaunchHook):

def execute(self):
project_entity = self.data["project_entity"]
project_settings = get_project_settings(project_entity.get("name"))
if not project_settings:
return
mxp_workspace = project_settings["max"].get("mxp_workspace")
# Ensure the hook would not cause possible error
# when using the old addon.
if mxp_workspace is None:
self.log.warning("No mxp workspace setting found in the "
"latest Max Addon.")
return

workdir = self.launch_context.env.get("AYON_WORKDIR")
if not workdir:
self.log.warning("BUG: Workdir is not filled.")
return

create_workspace_mxp(workdir, project_entity["name"])
create_workspace_mxp(workdir, mxp_workspace=mxp_workspace)
19 changes: 3 additions & 16 deletions client/ayon_max/mxp.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import os
from ayon_core.settings import get_project_settings
from ayon_core.lib import Logger


def create_workspace_mxp(workdir, project_name):
def create_workspace_mxp(workdir, mxp_workspace=None):
dst_filepath = os.path.join(workdir, "workspace.mxp")
if os.path.exists(dst_filepath):
return

if not os.path.exists(workdir):
os.makedirs(workdir)

project_settings = get_project_settings(project_name)
log = Logger.get_logger("create_workspace_mxp")
mxp_workspace = project_settings["max"].get("mxp_workspace")
# Ensure the hook would not cause possible error
# when using the old addon.
if mxp_workspace is None:
log.debug("No mxp workspace setting found in the "
"latest Max Addon. Please update to 0.1.8")
return

os.makedirs(workdir, exist_ok=True)
max_script = default_mxp_template()
if mxp_workspace.get("enabled_project_creation"):
max_script = mxp_workspace.get("mxp_workspace_script")
Expand Down Expand Up @@ -55,7 +43,6 @@ def default_mxp_template():
'Scenes=./',
'Sounds=./',
'[XReferenceDirs]',
'Dir1=./',
''
'Dir1=./'
))
return mxp_template

0 comments on commit a62d69c

Please sign in to comment.