generated from ynput/ayon-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ynput/core/enhancement/AY-5186_3dsmax-proj…
…ect-creation Max: Create/Set Project Folder when starting Max or task changed
- Loading branch information
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from ayon_applications import PreLaunchHook, LaunchTypes | ||
from ayon_max.mxp import create_workspace_mxp | ||
|
||
|
||
class PreCopyMxp(PreLaunchHook): | ||
"""Copy workspace.mxp to workdir. | ||
Hook `GlobalHostDataHook` must be executed before this hook. | ||
""" | ||
app_groups = {"3dsmax", "adsk_3dsmax"} | ||
launch_types = {LaunchTypes.local} | ||
|
||
def execute(self): | ||
max_setting = self.data["project_settings"]["max"] | ||
mxp_workspace = max_setting.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 | ||
enabled_project_creation = mxp_workspace.get("enabled_project_creation") | ||
if not enabled_project_creation: | ||
self.log.debug("3dsmax project creation is not enabled. " | ||
"Skipping creating workspace.mxp to workdir.") | ||
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, mxp_workspace=mxp_workspace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
from ayon_core.lib import Logger | ||
|
||
|
||
def create_workspace_mxp(workdir, mxp_workspace=None): | ||
dst_filepath = os.path.join(workdir, "workspace.mxp") | ||
if os.path.exists(dst_filepath): | ||
return | ||
|
||
log = Logger.get_logger("create_workspace_mxp") | ||
max_script = default_mxp_template() | ||
if mxp_workspace: | ||
if not mxp_workspace.get("enabled_project_creation"): | ||
log.debug("3dsmax project creation is disabled.") | ||
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 | ||
|
||
os.makedirs(workdir, exist_ok=True) | ||
with open(dst_filepath, "w") as mxp_file: | ||
mxp_file.write(max_script) | ||
|
||
return dst_filepath | ||
|
||
|
||
def default_mxp_template(): | ||
"""Return text script for the path configuration if | ||
users do not enable project creation in AYON project | ||
setting | ||
""" | ||
mxp_template = "\n".join(( | ||
'[Directories]', | ||
'Animations= ./', | ||
'Archives=./', | ||
'AutoBackup=./', | ||
'BitmapProxies=./', | ||
'Fluid Simulations=./', | ||
'Images=./', | ||
'MaxStart=./', | ||
'Previews=./', | ||
'RenderAssets=./', | ||
'RenderOutput= ./renders/3dsmax', | ||
'Scenes=./', | ||
'Sounds=./', | ||
'[XReferenceDirs]', | ||
'Dir1=./' | ||
)) | ||
return mxp_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters