Skip to content

Commit

Permalink
add callback for creating project before opening workfile
Browse files Browse the repository at this point in the history
  • Loading branch information
moonyuet committed May 6, 2024
1 parent ceea5d0 commit 7a028c4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions client/ayon_core/hosts/max/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def install(self):
self.menu = AYONMenu()

register_event_callback("taskChanged", on_task_changed)
register_event_callback("workfile.save.before", before_workfile_save)

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

def context_setting():
Expand All @@ -70,6 +69,7 @@ def context_setting():

rt.callbacks.addScript(rt.Name('postWorkspaceChange'),
self._deferred_menu_creation)

rt.NodeEventCallback(
nameChanged=lib.update_modifier_node_names)

Expand Down Expand Up @@ -200,13 +200,11 @@ def _set_project():
else:
raise

dst_filepath = os.path.join(workdir, "workspace.mxp")
rt.pathConfig.load(dst_filepath)
has_project = (
mxp_filepath = os.path.join(workdir, "workspace.mxp")
if os.path.exists(mxp_filepath):
rt.pathConfig.load(mxp_filepath)
rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir)
)
if not has_project:
rt.pathConfig.setCurrentProjectFolder(workdir)
rt.pathConfig.setCurrentProjectFolder(workdir)


def on_task_changed():
Expand All @@ -216,13 +214,17 @@ def on_task_changed():
rt.pathConfig.setCurrentProjectFolder(workdir)


def before_workfile_save(event):
def on_before_open():
project_name = get_current_project_name()
workdir_path = event["workdir_path"]
if workdir_path:
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, mxp_filepath)
rt.pathConfig.load(mxp_filepath)
if rt.pathConfig.getCurrentProjectFolder() != workdir_path:
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)


def load_custom_attribute_data():
Expand Down

0 comments on commit 7a028c4

Please sign in to comment.