Skip to content

Commit

Permalink
Merge pull request #22 from ynput/enhancement/AY-7169_Callback-action…
Browse files Browse the repository at this point in the history
…-for-project-creation-when-Max-launches

Set the correct project folder accordingly to Ayon workdir
  • Loading branch information
moonyuet authored Nov 20, 2024
2 parents 7d92d59 + 54f39cb commit 5755c97
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions client/ayon_max/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def install(self):
register_creator_plugin_path(CREATE_PATH)

_set_project()
lib.set_context_setting()

self.menu = AYONMenu()

register_event_callback("workfile.open.before", on_before_open)
self._has_been_setup = True

rt.callbacks.addScript(rt.Name('systemPostNew'), on_new)

rt.callbacks.addScript(rt.Name('filePostOpen'),
Expand Down Expand Up @@ -214,13 +214,17 @@ def containerise(name: str, nodes: list, context,
def _set_project():
project_name = get_current_project_name()
project_settings = get_project_settings(project_name)
workdir = os.getenv("AYON_WORKDIR")
os.makedirs(workdir, exist_ok=True)
rt.pathConfig.setCurrentProjectFolder(workdir)
enable_project_creation = project_settings["max"].get("enabled_project_creation")
if not enable_project_creation:
if enable_project_creation:
directory_count = rt.pathConfig.getProjectSubDirectoryCount()
autobackup_dir = rt.pathConfig.GetDir(rt.Name("autoback"))
os.makedirs(autobackup_dir, exist_ok=True)
log.debug("Project creation disabled. Skipping project creation.")
return
workdir = os.getenv("AYON_WORKDIR")

os.makedirs(workdir, exist_ok=True)
mxp_filepath = os.path.join(workdir, "workspace.mxp")
if os.path.exists(mxp_filepath):
rt.pathConfig.load(mxp_filepath)
Expand All @@ -229,7 +233,6 @@ def _set_project():
proj_dir = rt.pathConfig.getProjectSubDirectory(count)
if proj_dir:
os.makedirs(proj_dir, exist_ok=True)
rt.pathConfig.setCurrentProjectFolder(workdir)


def on_before_open():
Expand Down

0 comments on commit 5755c97

Please sign in to comment.