1

First time working with an API that isn't part of normal python lib that isn't installed using -pip. I'm using VS Code and trying to get python to import the API. But I'm coming up short. The Davinci Resolve documentation says to use these lines of code to get a script working.

RESOLVE_SCRIPT_API= "%PROGRAMDATAtest%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\"
RESOLVE_SCRIPT_LIB= "C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll"
PYTHONPATH= "%PYTHONPATH%;%RESOLVE_SCRIPT_API%\Modules\"

But I can't seem to find the right place for them. I've tired in my script file. I've tried creating a virtual environment and them in that way but that still didn't work. I think the best way for this to work would be VS Code to natively point to the folder path of the API. I've found the 'workspace.jason' file but I'm unsure how to add / append the above path strings to get it to work.

This was my best attempt at it.

{
    "folders": [
        {
            "path": "C:/Users/Nick/Desktop/Python",
            "dr_API": "%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting"
        }
    ],
    "settings": {
        "python.autoComplete.extraPaths": [
            
        ]
    }
}

Any help or insight would be much appreciated.

PS. I'm self taught so if this is something that is dumb to the formally trained, I apologize in advance.

I've found the Davinci Resolve documentation here:

DaVinciResolve-API-Docs

2
  • Speaking as someone who knows nothing about VS Code but does know Python -- you can always change sys.path to contain the extra directory instead of relying on PYTHONPATH to be used for lookups. Similarly, you can set os.environ['RESOLVE_SCRIPT_API'] and os.environ['RESOLVE_SCRIPT_LIB'] before you try to do the first import. BTW, do make sure the interpreter you're using is binary-compatible (same version, built with the same compiler with the same ABI target). Also, you may need to expand PROGRAMDATA yourself if you do it this way. Commented Feb 29, 2024 at 2:55
  • (I have Resolve Studio installed, but on MacOS rather than Windows, and I have no interest in interacting in any way with Microsoft products -- so I'm not in a place to reproduce the problem). Commented Feb 29, 2024 at 2:57

2 Answers 2

0

You could use a .vscode/settings.json , and add a setting python.envFile to refer to a .env file which contains these environment variables.

Content of settings.json

{ "python.envFile": "${workspaceFolder}/.env" }

Contents of .env file

PYTHONPATH="C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\Modules"
Sign up to request clarification or add additional context in comments.

Comments

0

I started today and faced same problem too, and with very little experience in python and some investigations today I think I should write a tutorial for someone like us.

On Windows

  1. Install python version >= 3.9 (as in my exp) or mind your existing python installations on your system.
  2. Set Environment variables: Go to Settings on Windows then find "env" then click Edit environment variables for your account then New... 3 variable (RESOLVE_SCRIPT_LIB is based on where you installed DR) Environment variables
  3. If you cannot run the script, do this step. Find real python version is being used by DaVinci Resolve: Open DR, in Menu choose Workspaces > Console choose Py3 then run each line of this python 3 script
    import sys
    pprint.pp(sys.path)
    
    then you may end up seeing output like this
    Py3> pprint.pp(sys.path)
    ['D:\\Blackmagic Design\\DaVinci Resolve',
     'E:\\System\\anaconda3\\python39.zip',
     'E:\\System\\anaconda3\\DLLs',
     'E:\\System\\anaconda3\\lib',
     'D:\\Blackmagic Design\\DaVinci Resolve',
     'E:\\System\\anaconda3',
     'E:\\System\\anaconda3\\lib\\site-packages',
     'E:\\System\\anaconda3\\lib\\site-packages\\win32',
     'E:\\System\\anaconda3\\lib\\site-packages\\win32\\lib',
     'E:\\System\\anaconda3\\lib\\site-packages\\Pythonwin']
    
    these paths contain the exact python version DR is using and you MUST use the same version that DR using to run the python automation script or the import DaVinciResolveScript as dvr_script will NOT load fusionscript.dll successfully. In my case E:\System\anaconda3 is where the python.exe is used to run in DR. If you accidentally installed more than one python (like me anaconda that I installed a long time ago then uninstalled it but it remained in that path, and python3.11 couple of months ago, I thought I can use python3.11 but it cannot load fusionscript.dll).
  4. Add python to PATH of environment variables: the python path you found in step 3 (E:\System\anaconda3 in my case). Remove all the other python path too.
  5. Create virtual environment for python (Optional)
  6. Start writing a script to test: save as test.py
    import DaVinciResolveScript as dvr_script
    resolve = dvr_script.scriptapp("Resolve")
    fusion = resolve.Fusion()
    projectManager = resolve.GetProjectManager()
    p = projectManager.CreateProject("Hello World")
    
  7. Run it by opening new cmd in the test.py script folder: python test.py

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.