From ee2a9512fef67ae56f1e46b8c47ac465f421b02d Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 9 May 2024 21:15:29 +0800 Subject: [PATCH] code clean up --- client/ayon_core/hosts/max/api/pipeline.py | 33 ++++--------------- client/ayon_core/hosts/max/{lib.py => mxp.py} | 13 +++----- 2 files changed, 11 insertions(+), 35 deletions(-) rename client/ayon_core/hosts/max/{lib.py => mxp.py} (74%) diff --git a/client/ayon_core/hosts/max/api/pipeline.py b/client/ayon_core/hosts/max/api/pipeline.py index 134dad1780..72778ca193 100644 --- a/client/ayon_core/hosts/max/api/pipeline.py +++ b/client/ayon_core/hosts/max/api/pipeline.py @@ -55,7 +55,6 @@ class MaxHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): self.menu = AYONMenu() register_event_callback("taskChanged", on_task_changed) - register_event_callback("workfile.open.before", on_before_open) self._has_been_setup = True def context_setting(): @@ -190,18 +189,12 @@ def containerise(name: str, nodes: list, context, def _set_project(): workdir = os.getenv("AYON_WORKDIR") - - try: - os.makedirs(workdir) - except OSError as e: - # An already existing working directory is fine. - if e.errno == errno.EEXIST: - pass - else: - raise - - mxp_filepath = os.path.join(workdir, "workspace.mxp") - if os.path.exists(mxp_filepath): + os.makedirs(workdir, exist_ok=True) + log.info("Updating 3dsMax workspace for task change to %s", workdir) + rt.pathConfig.setCurrentProjectFolder(workdir) + project_name = get_current_project_name() + mxp_filepath = create_workspace_mxp(workdir, project_name) + if mxp_filepath: rt.pathConfig.load(mxp_filepath) rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir) rt.pathConfig.setCurrentProjectFolder(workdir) @@ -211,19 +204,7 @@ def on_task_changed(): workdir = os.getenv("AYON_WORKDIR") if os.path.exists(workdir): log.info("Updating 3dsMax workspace for task change to %s", workdir) - rt.pathConfig.setCurrentProjectFolder(workdir) - - -def on_before_open(): - project_name = get_current_project_name() - workdir_path = os.getenv("AYON_WORKDIR") - if os.path.exists(workdir_path): - create_workspace_mxp(workdir_path, project_name) - mxp_filepath = os.path.join(workdir_path, "workspace.mxp") - if os.path.exists(mxp_filepath): - rt.pathConfig.load(mxp_filepath) - rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir_path) - rt.pathConfig.setCurrentProjectFolder(workdir_path) + _set_project() def load_custom_attribute_data(): diff --git a/client/ayon_core/hosts/max/lib.py b/client/ayon_core/hosts/max/mxp.py similarity index 74% rename from client/ayon_core/hosts/max/lib.py rename to client/ayon_core/hosts/max/mxp.py index 0d426b0733..1cfd814922 100644 --- a/client/ayon_core/hosts/max/lib.py +++ b/client/ayon_core/hosts/max/mxp.py @@ -3,7 +3,7 @@ from ayon_core.settings import get_project_settings from ayon_core.lib import Logger -def create_workspace_mxp(workdir, project_name, project_settings=None): +def create_workspace_mxp(workdir, project_name): dst_filepath = os.path.join(workdir, "workspace.mxp") if os.path.exists(dst_filepath): return @@ -11,8 +11,7 @@ def create_workspace_mxp(workdir, project_name, project_settings=None): if not os.path.exists(workdir): os.makedirs(workdir) - if not project_settings: - project_settings = get_project_settings(project_name) + 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 @@ -28,11 +27,7 @@ def create_workspace_mxp(workdir, project_name, project_settings=None): 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) - with open(dst_filepath, "w") as mxp_file: mxp_file.write(max_script) + + return dst_filepath