From 0e352e2b46c82f79b317e145a1f3704707d8241e Mon Sep 17 00:00:00 2001 From: Jesse Spielman Date: Mon, 22 Dec 2014 17:32:21 +0000 Subject: [PATCH] Reset projectroot on SG save/saveas This caught us out when we moved a project in from another job and the projectroot was wrong. This caused the export to spill into the original project rather than the the new save target. --- hooks/scene_operation_tk-hiero.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hooks/scene_operation_tk-hiero.py b/hooks/scene_operation_tk-hiero.py index d5605f5..9edffb8 100644 --- a/hooks/scene_operation_tk-hiero.py +++ b/hooks/scene_operation_tk-hiero.py @@ -83,10 +83,14 @@ def execute(self, operation, file_path, context, parent_action, file_version, re # save the current script: project = self._get_current_project() project.save() + + self.set_project_root(project) elif operation == "save_as": project = self._get_current_project() project.saveAs(file_path.replace(os.path.sep, "/")) + + self.set_project_root(project) elif operation == "reset": # do nothing and indicate scene was reset to empty @@ -117,3 +121,14 @@ def _get_current_project(self): raise TankError("Please select a Hiero Project!") return project + + + def set_project_root(self, project): + """ If we're saving inside this SGTK project, set the + projectroot. + """ + sgtk_project_path = self.parent.tank.project_path + + if (project.path().startswith(sgtk_project_path) and + not project.projectRoot().startswith(sgtk_project_path)): + project.setProjectRoot(sgtk_project_path)