diff --git a/pype/hooks/resolve/prelaunch.py b/pype/hooks/resolve/prelaunch.py index 0020677c4c..ebf101dc1d 100644 --- a/pype/hooks/resolve/prelaunch.py +++ b/pype/hooks/resolve/prelaunch.py @@ -26,6 +26,9 @@ class ResolvePrelaunch(PypeHook): if not env: env = os.environ + env["PRE_PYTHON_SCRIPT"] = os.path.normpath(env["PRE_PYTHON_SCRIPT"]) + self.log.info(env["PRE_PYTHON_SCRIPT"]) + try: __import__("pype.resolve") __import__("pyblish") diff --git a/pype/resolve/pre_python_console_script.py b/pype/resolve/pre_python_console_script.py new file mode 100644 index 0000000000..1c1aceaddd --- /dev/null +++ b/pype/resolve/pre_python_console_script.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import time +from python_get_resolve import GetResolve + +wait_delay = 2.5 +wait = 0.00 +ready = None +while True: + try: + # Create project and set parameters: + resolve = GetResolve() + PM = resolve.GetProjectManager() + P = PM.GetCurrentProject() + if P.GetName() == "Untitled Project": + ready = None + else: + ready = True + except AttributeError: + pass + + if ready is None: + time.sleep(wait_delay) + print(f"Waiting {wait}s for Resolve to be open inproject") + wait += wait_delay + else: + break diff --git a/pype/resolve/python_get_resolve.py b/pype/resolve/python_get_resolve.py new file mode 100644 index 0000000000..862a5bb758 --- /dev/null +++ b/pype/resolve/python_get_resolve.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +""" +This file serves to return a DaVinci Resolve object +""" + +import sys + +def GetResolve(): + try: + # The PYTHONPATH needs to be set correctly for this import statement to work. + # An alternative is to import the DaVinciResolveScript by specifying absolute path (see ExceptionHandler logic) + import DaVinciResolveScript as bmd + except ImportError: + if sys.platform.startswith("darwin"): + expectedPath="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules/" + elif sys.platform.startswith("win") or sys.platform.startswith("cygwin"): + import os + expectedPath=os.getenv('PROGRAMDATA') + "\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules\\" + elif sys.platform.startswith("linux"): + expectedPath="/opt/resolve/libs/Fusion/Modules/" + + # check if the default path has it... + print("Unable to find module DaVinciResolveScript from $PYTHONPATH - trying default locations") + try: + import imp + bmd = imp.load_source('DaVinciResolveScript', expectedPath+"DaVinciResolveScript.py") + except ImportError: + # No fallbacks ... report error: + print("Unable to find module DaVinciResolveScript - please ensure that the module DaVinciResolveScript is discoverable by python") + print("For a default DaVinci Resolve installation, the module is expected to be located in: "+expectedPath) + sys.exit() + + return bmd.scriptapp("Resolve")