Scripting API - Batch Exporting .drps

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

danigarvire

  • Posts: 2
  • Joined: Tue Apr 01, 2025 3:12 pm
  • Real Name: DANI

Scripting API - Batch Exporting .drps

PostTue Apr 01, 2025 3:21 pm

Subject: Issues with Exporting Projects via DaVinci Resolve API Script

Hello everyone! Im quite new to blackmagic and Im currently trying to create a script to automate the export of all my projects from DaVinci Resolve using the scripting API. However, I've encountered some issues that I can't seem to resolve, and I'm hoping for some guidance from the community.

Setup:

DaVinci Resolve version: [18.6]
Operating System: [MacOS Sonoma 14.5]
Python version: [3.10]

Objective:

I want to export all projects in my current project library to .drp files without manually opening each project.

Script Overview:

Here's a simplified version of the script I'm using:

Code: Select all
import os
import DaVinciResolveScript as dvr

resolve = dvr.scriptapp("Resolve")

if resolve:
    project_manager = resolve.GetProjectManager()
    if project_manager:
        all_projects = project_manager.GetProjectListInCurrentFolder()
        for project_name in all_projects:
            project = project_manager.LoadProject(project_name)
            if project:
                export_path = f"/path/to/export/{project_name}.drp"
                success = project.ExportProject(export_path)
                if not success:
                    print(f"Failed to export project: {project_name}")
            else:
                print(f"Failed to load project: {project_name}")



Issues Encountered:


Error Message: 'NoneType' object is not callable when attempting to use ExportProject.
Inconsistent Project List: The list of projects sometimes appears empty or incomplete.
Project Loading: Some projects fail to load, returning None.

Troubleshooting Steps Taken:

Verified connection to DaVinci Resolve and access to the Project Manager.
Checked permissions for the export directory.
Attempted manual export through the DaVinci Resolve interface, which works fine.
Reviewed the API documentation for correct usage of ExportProject.

Questions:

Is there a known issue with the ExportProject method in certain versions of the API?
Are there additional steps required to ensure projects are loaded and exported correctly?
Could there be a configuration or permission setting in DaVinci Resolve affecting the script?
Any insights or suggestions would be greatly appreciated. Thank you in advance for your help!

Best regards,
Daniel
Offline

Christoph Schmid

  • Posts: 825
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Scripting API - Batch Exporting .drps

PostWed Apr 02, 2025 7:35 pm

There are 2 mistakes in your script:
ExportProject() is a method of project_manager not of project.
ExportProject() needs project_name and export_path.

Change:
Code: Select all
success = project.ExportProject(export_path)

To:
Code: Select all
success = project_manager.ExportProject(project_name, export_path)

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

danigarvire

  • Posts: 2
  • Joined: Tue Apr 01, 2025 3:12 pm
  • Real Name: DANI

Re: Scripting API - Batch Exporting .drps

PostFri Apr 04, 2025 9:09 am

Would there be a way for the script to batch export all found projects? It would be optimal to not to need to specify project. I work in several projects at once and nearly once a week a new project enters that we need backup aswell. The best way to go would be to batch export all weekly essentially.
Offline

Christoph Schmid

  • Posts: 825
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Scripting API - Batch Exporting .drps

PostMon Apr 07, 2025 10:17 am

If I read your code correctly it should already do this ?!
But you have to give it a name otherwise it overwrites itself and you have to close the project after export:
Code: Select all
export_path = "export/to/path/" # end with /

project_manager = resolve.GetProjectManager()
project_names = project_manager.GetProjectListInCurrentFolder()
for project_name in project_names:
    project = project_manager.LoadProject(project_name)
    name = export_path + project_name + ".drp"
    project_manager.ExportProject(project_name, name)
    project_manager.CloseProject(project)

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

Marcus Herrick

  • Posts: 53
  • Joined: Thu Aug 23, 2012 8:53 pm

Re: Scripting API - Batch Exporting .drps

PostTue Apr 08, 2025 4:05 am

Here's my version of this script, which includes a GUI and creates sub folders for bins.



Code: Select all


 
local ui = fu.UIManager
local disp = bmd.UIDispatcher(ui)

 
win = disp:AddWindow({
  ID = 'MyWin',
  WindowTitle = 'Export All Resolve projects in Database v1',
  Geometry = {100, 100, 500, 200},
  Spacing = 10,
  Margin = 30,
       
  ui:VGroup{
    ID = 'root',
    Weight = 0.5,
    -- Add your GUI elements here:
   

 
    -- Open Folder
    ui:HGroup{


      ui:Button{
        ID = 'FolderButton',
        Text = 'Select a Export Folder',
        Weight = 0.25,
      },
     
            ui:LineEdit{ ID = "FolderTxt",
            PlaceholderText = "Select Destination Folder",
            --Text = "localhost",
            Weight = 1.5,
            MinimumSize = {250, 24} },
   
    },
   
   
 
             ui:Label{
        ID='ExampleTxt',
        Text = '',
        Weight = 1.5,
      },
 
 
 
        -- Export Button
    ui:HGroup{

 
      ui:Button{
        ID = 'RunButton',
        Text = 'Export',
        Weight = 0.25,
      },
   
          },
   
         
      ui:HGroup{
             ui:Label{
        ID='Made By',
        Text = 'Written by Marcus Herrick',
        Weight = 0.25,
                     },
               },
   
  },
})
 
 

 
 
-- Add your GUI element based event functions here:
itm = win:GetItems()

 
-- The window was closed
function win.On.MyWin.Close(ev)
  disp:ExitLoop()
end
 

 -- FILL COMBO BOX ment based event functions here:
itm = win:GetItems()
 

-- The Open Folder button was clicked
function win.On.FolderButton.Clicked(ev)
  print('Open Folder Button Clicked')
  selectedPath = tostring(fu:RequestDir())
  print('[Folder] ', selectedPath)
  itm.FolderTxt.Text = selectedPath
end


-- If you manually change the text
function win.On.FolderTxt.TextChanged(ev)
    print("Folder location changed to: " .. itm.FolderTxt.Text)
   selectedPath = itm.FolderTxt.Text
end



 -- The run button was clicked
function win.On.RunButton.Clicked(ev)


RootFolder = itm.FolderTxt.Text
LayerCounter = 0
NewDir = RootFolder


      FolderArray = {}

      local function DisplayProjectsWithinFolder( projectManager, folderString, projectString )
         folderString = folderString or "- "
         projectString = projectString or "  "

         folderString = "  "..folderString
         projectString = "  "..projectString

         -- record layer depth here
            LayerCounter = LayerCounter + 1
               print('LayerCounter' .. LayerCounter)   

         local projects = projectManager:GetProjectsInCurrentFolder()
         for projectIndex in pairs(projects) do


            if projectManager:ExportProject(projects[projectIndex], NewDir .. projects[projectIndex], True) then
               
               itm.ExampleTxt.Text = 'Exporting: ' .. NewDir .. projects[projectIndex]
               print('projectString' .. NewDir .. projects[projectIndex])
            end
         end

         local folders = projectManager:GetFoldersInCurrentFolder()
         for folderIndex in pairs(folders) do
            
            if projectManager:OpenFolder(folders[folderIndex]) then
               
                  FolderArray[LayerCounter] = folders[folderIndex]
                  SubFolder = ""
                        
                     for depth=1, LayerCounter do                        
                           
                           SubFolder = SubFolder .. string.gsub(FolderArray[depth], "%s+", "_") .. [[/]]
                     end
                     NewDir = RootFolder .. SubFolder      
                     print('NewDir ' .. NewDir)

      
               MakeDir = "mkdir " .. NewDir
               itm.ExampleTxt.Text = 'Making Folder: ' .. NewDir
               os.execute(MakeDir)            
               DisplayProjectsWithinFolder(projectManager, folderString, projectString)
               projectManager:GotoParentFolder()
               LayerCounter = LayerCounter - 1
            end
         end
         itm.ExampleTxt.Text = 'Complete'
      end

      

      local function DisplayProjectTree( resolve )
         projectManager = resolve:GetProjectManager()
         projectManager:GotoRootFolder()

         DisplayProjectsWithinFolder(projectManager)
      end

      resolve = Resolve()

      DisplayProjectTree(resolve)


end
 

win:Show()
disp:RunLoop()
win:Hide()

Offline
User avatar

Igor Riđanović

  • Posts: 1650
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Scripting API - Batch Exporting .drps

PostWed Apr 09, 2025 1:32 am

www.metafide.com - DaVinci Resolve™ Apps

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 3 guests