From b8d6e2181fff35882d4496beb5ec791cd9ad0993 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Sun, 20 Feb 2022 20:17:56 +0100 Subject: [PATCH 1/5] Fix #2714 houdini open last workfile --- openpype/hooks/pre_add_last_workfile_arg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openpype/hooks/pre_add_last_workfile_arg.py b/openpype/hooks/pre_add_last_workfile_arg.py index 653f97b3dd..922dde49bb 100644 --- a/openpype/hooks/pre_add_last_workfile_arg.py +++ b/openpype/hooks/pre_add_last_workfile_arg.py @@ -17,6 +17,7 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): "nuke", "nukex", "hiero", + "houdini", "nukestudio", "blender", "photoshop", From 43010a490ebcbe2bbbe3a882e8a10d57cf415a16 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 21 Feb 2022 15:07:00 +0100 Subject: [PATCH 2/5] Fix OpenPype not initialized on Houdini launch when opening with last workfile --- openpype/hooks/pre_add_last_workfile_arg.py | 40 +++++++++++++++++-- .../startup/scripts/openpype_launch.py | 40 +++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 openpype/hosts/houdini/startup/scripts/openpype_launch.py diff --git a/openpype/hooks/pre_add_last_workfile_arg.py b/openpype/hooks/pre_add_last_workfile_arg.py index 922dde49bb..4797b61580 100644 --- a/openpype/hooks/pre_add_last_workfile_arg.py +++ b/openpype/hooks/pre_add_last_workfile_arg.py @@ -17,7 +17,6 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): "nuke", "nukex", "hiero", - "houdini", "nukestudio", "blender", "photoshop", @@ -25,7 +24,7 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): "afftereffects" ] - def execute(self): + def get_last_workfile(self): if not self.data.get("start_last_workfile"): self.log.info("It is set to not start last workfile on start.") return @@ -39,5 +38,38 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): self.log.info("Current context does not have any workfile yet.") return - # Add path to workfile to arguments - self.launch_context.launch_args.append(last_workfile) + return last_workfile + + def execute(self): + + last_workfile = self.get_last_workfile() + if last_workfile: + # Add path to workfile to arguments + self.launch_context.launch_args.append(last_workfile) + + +class AddLastWorkfileToLaunchArgsHoudini(AddLastWorkfileToLaunchArgs): + """Add last workfile path to launch arguments - Houdini specific""" + app_groups = ["houdini"] + + def execute(self): + + last_workfile = self.get_last_workfile() + if last_workfile: + # Whenever a filepath is passed to Houdini then the startup + # scripts 123.py and houdinicore.py won't be triggered. Thus + # OpenPype will not initialize correctly. As such, whenever + # we pass a workfile we first explicitly pass a startup + # script to enforce it to run - which will load the last passed + # argument as workfile directly. + pype_root = os.environ["OPENPYPE_REPOS_ROOT"] + startup_path = os.path.join( + pype_root, "openpype", "hosts", "houdini", "startup" + ) + startup_script = os.path.join(startup_path, + "scripts", + "openpype_launch.py") + self.launch_context.launch_args.append(startup_script) + + # Add path to workfile to arguments + self.launch_context.launch_args.append(last_workfile) diff --git a/openpype/hosts/houdini/startup/scripts/openpype_launch.py b/openpype/hosts/houdini/startup/scripts/openpype_launch.py new file mode 100644 index 0000000000..1a9069dbc6 --- /dev/null +++ b/openpype/hosts/houdini/startup/scripts/openpype_launch.py @@ -0,0 +1,40 @@ +import os +import sys +import avalon.api +from openpype.hosts.houdini import api +import openpype.hosts.houdini.api.workio + +import hou + + +def is_workfile(path): + if not path: + return + + if not os.path.exists(path): + return False + + _, ext = os.path.splitext(path) + if ext in openpype.hosts.houdini.api.workio.file_extensions(): + return True + + +def main(): + print("Installing OpenPype ...") + avalon.api.install(api) + + args = sys.argv + if args and is_workfile(args[-1]): + # If the last argument is a Houdini file open it directly + workfile_path = args[-1].replace("\\", "/") + print("Opening workfile on launch: {}".format(workfile_path)) + + # We don't use `workio.open_file` because we want to explicitly ignore + # load warnings. Otherwise Houdini will fail to start if a scene load + # produces e.g. errors on missing plug-ins + hou.hipFile.load(workfile_path, + suppress_save_prompt=True, + ignore_load_warnings=True) + + +main() From 1cfdbcb2a14d36cef5bb920b5ae20f74cc476623 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 21 Feb 2022 15:55:32 +0100 Subject: [PATCH 3/5] Use pythonrc.py file for Houdini start instead of 123.py/houdinicore.py --- .../123.py => python2.7libs/pythonrc.py} | 0 .../pythonrc.py} | 0 .../startup/scripts/openpype_launch.py | 40 ------------------- 3 files changed, 40 deletions(-) rename openpype/hosts/houdini/startup/{scripts/123.py => python2.7libs/pythonrc.py} (100%) rename openpype/hosts/houdini/startup/{scripts/houdinicore.py => python3.7libs/pythonrc.py} (100%) delete mode 100644 openpype/hosts/houdini/startup/scripts/openpype_launch.py diff --git a/openpype/hosts/houdini/startup/scripts/123.py b/openpype/hosts/houdini/startup/python2.7libs/pythonrc.py similarity index 100% rename from openpype/hosts/houdini/startup/scripts/123.py rename to openpype/hosts/houdini/startup/python2.7libs/pythonrc.py diff --git a/openpype/hosts/houdini/startup/scripts/houdinicore.py b/openpype/hosts/houdini/startup/python3.7libs/pythonrc.py similarity index 100% rename from openpype/hosts/houdini/startup/scripts/houdinicore.py rename to openpype/hosts/houdini/startup/python3.7libs/pythonrc.py diff --git a/openpype/hosts/houdini/startup/scripts/openpype_launch.py b/openpype/hosts/houdini/startup/scripts/openpype_launch.py deleted file mode 100644 index 1a9069dbc6..0000000000 --- a/openpype/hosts/houdini/startup/scripts/openpype_launch.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import sys -import avalon.api -from openpype.hosts.houdini import api -import openpype.hosts.houdini.api.workio - -import hou - - -def is_workfile(path): - if not path: - return - - if not os.path.exists(path): - return False - - _, ext = os.path.splitext(path) - if ext in openpype.hosts.houdini.api.workio.file_extensions(): - return True - - -def main(): - print("Installing OpenPype ...") - avalon.api.install(api) - - args = sys.argv - if args and is_workfile(args[-1]): - # If the last argument is a Houdini file open it directly - workfile_path = args[-1].replace("\\", "/") - print("Opening workfile on launch: {}".format(workfile_path)) - - # We don't use `workio.open_file` because we want to explicitly ignore - # load warnings. Otherwise Houdini will fail to start if a scene load - # produces e.g. errors on missing plug-ins - hou.hipFile.load(workfile_path, - suppress_save_prompt=True, - ignore_load_warnings=True) - - -main() From 065c6a092fdcab6920347ed69ea0b30de474afb3 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 21 Feb 2022 15:56:07 +0100 Subject: [PATCH 4/5] Revert separation of Houdini last workfile code --- openpype/hooks/pre_add_last_workfile_arg.py | 35 ++------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/openpype/hooks/pre_add_last_workfile_arg.py b/openpype/hooks/pre_add_last_workfile_arg.py index 4797b61580..caebd7d034 100644 --- a/openpype/hooks/pre_add_last_workfile_arg.py +++ b/openpype/hooks/pre_add_last_workfile_arg.py @@ -17,6 +17,7 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): "nuke", "nukex", "hiero", + "houdini", "nukestudio", "blender", "photoshop", @@ -24,7 +25,7 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): "afftereffects" ] - def get_last_workfile(self): + def execute(self): if not self.data.get("start_last_workfile"): self.log.info("It is set to not start last workfile on start.") return @@ -38,38 +39,6 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): self.log.info("Current context does not have any workfile yet.") return - return last_workfile - - def execute(self): - - last_workfile = self.get_last_workfile() if last_workfile: # Add path to workfile to arguments self.launch_context.launch_args.append(last_workfile) - - -class AddLastWorkfileToLaunchArgsHoudini(AddLastWorkfileToLaunchArgs): - """Add last workfile path to launch arguments - Houdini specific""" - app_groups = ["houdini"] - - def execute(self): - - last_workfile = self.get_last_workfile() - if last_workfile: - # Whenever a filepath is passed to Houdini then the startup - # scripts 123.py and houdinicore.py won't be triggered. Thus - # OpenPype will not initialize correctly. As such, whenever - # we pass a workfile we first explicitly pass a startup - # script to enforce it to run - which will load the last passed - # argument as workfile directly. - pype_root = os.environ["OPENPYPE_REPOS_ROOT"] - startup_path = os.path.join( - pype_root, "openpype", "hosts", "houdini", "startup" - ) - startup_script = os.path.join(startup_path, - "scripts", - "openpype_launch.py") - self.launch_context.launch_args.append(startup_script) - - # Add path to workfile to arguments - self.launch_context.launch_args.append(last_workfile) From c03f6ec0b1e638e5864e7ca20a725118169c24d0 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 21 Feb 2022 15:56:58 +0100 Subject: [PATCH 5/5] Remove redundant if statement that didn't get reverted --- openpype/hooks/pre_add_last_workfile_arg.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openpype/hooks/pre_add_last_workfile_arg.py b/openpype/hooks/pre_add_last_workfile_arg.py index caebd7d034..922dde49bb 100644 --- a/openpype/hooks/pre_add_last_workfile_arg.py +++ b/openpype/hooks/pre_add_last_workfile_arg.py @@ -39,6 +39,5 @@ class AddLastWorkfileToLaunchArgs(PreLaunchHook): self.log.info("Current context does not have any workfile yet.") return - if last_workfile: - # Add path to workfile to arguments - self.launch_context.launch_args.append(last_workfile) + # Add path to workfile to arguments + self.launch_context.launch_args.append(last_workfile)