Skip to content

Commit

Permalink
add enable option for setting up the project creation based on mxp wo…
Browse files Browse the repository at this point in the history
…rkspace in the project setting
  • Loading branch information
moonyuet committed May 7, 2024
1 parent 2dd1156 commit 8e60492
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
7 changes: 4 additions & 3 deletions client/ayon_core/hosts/max/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
25 changes: 18 additions & 7 deletions client/ayon_core/hosts/max/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 14 additions & 3 deletions server_addon/max/server/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 8e60492

Please sign in to comment.