diff --git a/openpype/hosts/max/addon.py b/openpype/hosts/max/addon.py index 734b87dd21..d3245bbc7e 100644 --- a/openpype/hosts/max/addon.py +++ b/openpype/hosts/max/addon.py @@ -14,3 +14,10 @@ class MaxAddon(OpenPypeModule, IHostAddon): def get_workfile_extensions(self): return [".max"] + + def get_launch_hook_paths(self, app): + if app.host_name != self.host_name: + return [] + return [ + os.path.join(MAX_HOST_DIR, "hooks") + ] diff --git a/openpype/hosts/max/hooks/inject_python.py b/openpype/hosts/max/hooks/inject_python.py new file mode 100644 index 0000000000..d9753ccbd8 --- /dev/null +++ b/openpype/hosts/max/hooks/inject_python.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +"""Pre-launch hook to inject python environment.""" +from openpype.lib import PreLaunchHook +import os + + +class InjectPythonPath(PreLaunchHook): + """Inject OpenPype environment to 3dsmax. + + Note that this works in combination whit 3dsmax startup script that + is translating it back to PYTHONPATH for cases when 3dsmax drops PYTHONPATH + environment. + + Hook `GlobalHostDataHook` must be executed before this hook. + """ + app_groups = ["3dsmax"] + + def execute(self): + self.launch_context.env["MAX_PYTHONPATH"] = os.environ["PYTHONPATH"] diff --git a/openpype/hosts/max/startup/startup.ms b/openpype/hosts/max/startup/startup.ms index aee40eb6bc..b80ead4b74 100644 --- a/openpype/hosts/max/startup/startup.ms +++ b/openpype/hosts/max/startup/startup.ms @@ -2,8 +2,11 @@ ( local sysPath = dotNetClass "System.IO.Path" local sysDir = dotNetClass "System.IO.Directory" - local localScript = getThisScriptFilename() + local localScript = getThisScriptFilename() local startup = sysPath.Combine (sysPath.GetDirectoryName localScript) "startup.py" + local pythonpath = systemTools.getEnvVariable "MAX_PYTHONPATH" + systemTools.setEnvVariable "PYTHONPATH" pythonpath + python.ExecuteFile startup ) \ No newline at end of file