← All DaVinci Resolve API guides
DaVinci Resolve APIIntermediateAudio

How to Create Missing Audio Tracks with the DaVinci Resolve API

Check GetTrackCount and add tracks with AddTrack("audio") until the requested track index exists

Build a helper that guarantees A1, A2, A3, or another requested audio track exists before a later AppendToTimeline operation targets it.

API

Resolve Scripting API

Language

Python

Resolve

19–20+

Requires

Running Resolve

Syntax

result = api_method()

Parameters

  • The relevant arguments are shown in the complete working example below. Validate paths, object types, and required project state before calling the API method.

Returns

Always validate the returned object, list, identifier, or boolean before continuing to the next automation step.

Complete working Python exampleuse it as a starting point for your own script
import os
import sys
from pathlib import Path


def import_resolve_module():
    try:
        import DaVinciResolveScript as dvr
        return dvr
    except ImportError:
        search_paths = [
            os.environ.get("RESOLVE_SCRIPT_API", ""),
            os.environ.get("RESOLVE_MODULES", ""),
            r"C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules",
            "/opt/resolve/Developer/Scripting/Modules",
            "/opt/BlackmagicDesign/DaVinciResolve/Developer/Scripting/Modules",
            "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules",
            str(Path.home() / "Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules"),
        ]
        for path in search_paths:
            if path and os.path.isdir(path) and path not in sys.path:
                sys.path.append(path)
        import DaVinciResolveScript as dvr
        return dvr


def safe_call(obj, name, *args, **kwargs):
    try:
        fn = getattr(obj, name, None)
        if callable(fn):
            return fn(*args, **kwargs)
    except Exception:
        return None
    return None


def get_project_and_timeline():
    dvr = import_resolve_module()
    resolve = dvr.scriptapp("Resolve")
    if not resolve:
        raise RuntimeError("DaVinci Resolve API is unavailable")

    project_manager = safe_call(resolve, "GetProjectManager")
    project = safe_call(project_manager, "GetCurrentProject") if project_manager else None
    if not project:
        raise RuntimeError("No DaVinci Resolve project is open")

    timeline = safe_call(project, "GetCurrentTimeline")
    if not timeline:
        raise RuntimeError("No active Timeline")

    return resolve, project, timeline


def ensure_audio_track(timeline, track_index: int) -> int:
    if track_index < 1:
        raise ValueError("track_index must start at 1")

    count = int(safe_call(timeline, "GetTrackCount", "audio") or 0)
    while count < track_index:
        if not safe_call(timeline, "AddTrack", "audio"):
            raise RuntimeError(f"Could not create audio track A{count + 1}")
        count += 1
    return count


resolve, project, timeline = get_project_and_timeline()
tracks_after = ensure_audio_track(timeline, 3)
print("Audio tracks after check:", tracks_after)

Guide

What the helper does

The function reads the current audio-track count and repeatedly calls AddTrack("audio") until the requested track index exists. It returns the resulting count so the caller can verify the final structure.

Why track_index starts at 1

Resolve addresses Timeline tracks as A1, A2, A3 and V1, V2, V3. A trackIndex of 0 is therefore not a valid destination for this workflow.

A practical use case

Before placing music on A3 or sound effects on A2, an automation script can call this helper first and only then perform AppendToTimeline. That makes the same script more robust across projects with different initial track layouts.

How the example works

1

Connect to Resolve

Establish a Resolve Scripting API connection and stop early if the application object is unavailable.

2

Validate the current context

Check the active project, Timeline, Media Pool, source paths, or Render Queue state required by this specific operation.

3

Run the core API operation

Execute the operation demonstrated in this guide: how to create missing audio tracks with the davinci resolve api.

4

Validate the result

Check the returned value before the workflow continues. Resolve methods often signal an unavailable object or failed operation with None, False, or an empty result.

Resolve API notes

  • AddTrack("audio") can return False when Resolve cannot create a track in the current Timeline state.
  • Read GetTrackCount again if you need to verify the structure after creation.
  • AddTrack changes the Timeline, so call it only when a missing track actually needs to be created.
  • Use AddTrack("video") for video tracks.

Common errors

Resolve API is unavailable

Reason: Resolve is closed or Python cannot import/use DaVinciResolveScript.

Fix: Start Resolve and verify the Developer/Scripting/Modules path from the same Python interpreter used by the script.

The method returns None or False

Reason: A required project, Timeline, clip, preset, path, or application state is missing.

Fix: Validate each input and add explicit result checks after important Resolve API calls.

The script only works on one workstation

Reason: Paths or environment assumptions are hard-coded for a single operating system or machine.

Fix: Move paths into configuration and support the required Windows, Linux, and macOS locations explicitly.

Next step

Continue only after the current operation has returned the expected Resolve object or result.

Related API guides