add enable option for setting up the project creation based on mxp workspace in the project setting

This commit is contained in:
Kayla Man 2024-05-07 17:50:33 +08:00
parent 2dd1156575
commit 8e60492da4
3 changed files with 36 additions and 13 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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 @@ DEFAULT_VALUES = {
"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": {