diff --git a/client/ayon_core/hosts/max/api/pipeline.py b/client/ayon_core/hosts/max/api/pipeline.py index 0aca14e820..134dad1780 100644 --- a/client/ayon_core/hosts/max/api/pipeline.py +++ b/client/ayon_core/hosts/max/api/pipeline.py @@ -217,11 +217,12 @@ def on_task_changed(): def on_before_open(): project_name = get_current_project_name() workdir_path = os.getenv("AYON_WORKDIR") - if not os.path.exists(workdir_path): + if os.path.exists(workdir_path): create_workspace_mxp(workdir_path, project_name) mxp_filepath = os.path.join(workdir_path, "workspace.mxp") - rt.pathConfig.load(mxp_filepath) - rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir_path) + if os.path.exists(mxp_filepath): + rt.pathConfig.load(mxp_filepath) + rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir_path) rt.pathConfig.setCurrentProjectFolder(workdir_path) diff --git a/client/ayon_core/hosts/max/lib.py b/client/ayon_core/hosts/max/lib.py index 7b6499e299..ddffa917d9 100644 --- a/client/ayon_core/hosts/max/lib.py +++ b/client/ayon_core/hosts/max/lib.py @@ -13,18 +13,29 @@ def create_workspace_mxp(workdir, project_name, project_settings=None): if not project_settings: project_settings = get_project_settings(project_name) - max_script = project_settings["max"].get("mxp_workspace") - # TODO: add ProjectFolder={workdir} into the max_script + 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 + if not mxp_workspace.get("enabled"): + log.debug("Mxp workspace disabled in the project settings." + " Skipping action.") + return + max_script = mxp_workspace.get("mxp_workspace_script") + # Skip if mxp script in settings is empty + if not max_script: + log.debug("File 'workspace.mxp' not created. Settings value is empty.") + return + edited_script = "\n".join(( '[Directories]', f'ProjectFolder={workdir}' )) max_script = max_script.replace("[Directories]", edited_script) - # Skip if mxp script in settings is empty - if not max_script: - log = Logger.get_logger("create_workspace_mxp") - log.debug("File 'workspace.mxp' not created. Settings value is empty.") - return with open(dst_filepath, "w") as mxp_file: mxp_file.write(max_script) diff --git a/server_addon/max/server/settings/main.py b/server_addon/max/server/settings/main.py index e1411e1119..2243a2cca2 100644 --- a/server_addon/max/server/settings/main.py +++ b/server_addon/max/server/settings/main.py @@ -21,6 +21,13 @@ def unit_scale_enum(): ] +class MxpWorkspaceSettings(BaseSettingsModel): + enabled: bool = SettingsField(False, title="Enabled") + mxp_workspace_script: str = SettingsField( + title="Max mxp Workspace", widget="textarea" + ) + + class UnitScaleSettings(BaseSettingsModel): enabled: bool = SettingsField(True, title="Enabled") scene_unit_scale: str = SettingsField( @@ -46,8 +53,9 @@ class MaxSettings(BaseSettingsModel): default_factory=UnitScaleSettings, title="Set Unit Scale" ) - mxp_workspace: str = SettingsField( - title="Max mxp Workspace", widget="textarea" + mxp_workspace: MxpWorkspaceSettings = SettingsField( + default_factory=MxpWorkspaceSettings, + title="Max Workspace" ) imageio: ImageIOSettings = SettingsField( default_factory=ImageIOSettings, @@ -103,7 +111,10 @@ class MaxSettings(BaseSettingsModel): "enabled": True, "scene_unit_scale": "Centimeters" }, - "mxp_workspace": DEFAULT_MXP_WORKSPACE_SETTINGS, + "mxp_workspace": { + "enabled": False, + "mxp_workspace_script": DEFAULT_MXP_WORKSPACE_SETTINGS + }, "RenderSettings": DEFAULT_RENDER_SETTINGS, "CreateReview": DEFAULT_CREATE_REVIEW_SETTINGS, "PointCloud": {