import sys def load_source(module_name, file_path): if sys.version_info[0] >= 3 and sys.version_info[1] >= 5: import importlib.util module = None spec = importlib.util.spec_from_file_location(module_name, file_path) if spec: module = importlib.util.module_from_spec(spec) if module: sys.modules[module_name] = module spec.loader.exec_module(module) return module else: import imp return imp.load_source(module_name, file_path) 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/Developer/Scripting/Modules/" # check if the default path has it... print("Unable to find module DaVinciResolveScript from $PYTHONPATH - trying default locations") try: load_source('DaVinciResolveScript', expectedPath + "DaVinciResolveScript.py") import DaVinciResolveScript as bmd except Exception as ex: # 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) print(ex) sys.exit() return bmd.scriptapp("Resolve") import re def increment_timeline(s): def f(m): number = m.group(1) num_digits = len(number) if number: number = int(number) else: number = 0 return str(number+1).zfill(num_digits) return re.sub(r'(\d*)$', f, s, count=1) import sys import os lib_path = os.getenv("RESOLVE_SCRIPT_LIB") projectManager = resolve.GetProjectManager() project = projectManager.GetCurrentProject() timeline = project.GetCurrentTimeline() mediapool = project.GetMediaPool() name = timeline.GetName() newname = increment_timeline(name) new = timeline.DuplicateTimeline(newname) project.SetCurrentTimeline(new)