help troubleshooting Lua script to import Titles from CSV

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline
User avatar

spinhead

  • Posts: 11
  • Joined: Sun Mar 01, 2020 6:39 pm
  • Location: PHX AZ
  • Real Name: Joel D Canfield

help troubleshooting Lua script to import Titles from CSV

PostFri Jun 13, 2025 5:06 pm

New to DaVinci Resolve, new to Lua scripting.

Asked ChatGPT to write a script to let me import Titles from a text file. (My goal is to create lyric videos for my original songs, and avoid copy/pasting one line of the song at a time into a 3-6-minute video timeline.) It created the script below. Running it from "Workspace | Scripts" doesn't appear to do anything. Running it in the console thusly
Code: Select all
Lua> lua TimelineTitlesFromCSV.lua

throws this error
Code: Select all
[string "???"]:1: '=' expected near 'TimelineTitlesFromCSV'

Running v20 Build 49 on Mac Sequoia 15.5

The script:
Code: Select all
-- DaVinci Resolve Script: Import Titles with Multiline, Justification, Font, and Font Size

resolve = Resolve()
pm = resolve:GetProjectManager()
proj = pm:GetCurrentProject()
tl = proj:GetCurrentTimeline()

if not tl then
    print("No active timeline.")
    return
end

-- === CONFIGURATION ===

io.write("Enter the name of the CSV file (e.g., titles.csv): ")
local userInput = io.read()
local csvPath = "/Users/joel/Documents/Blackmagic Design/DaVinci Resolve/Import/" .. userInput


local defaultFont = "Open Sans"
local defaultFontSize = 0.08
local color = {1, 1, 1, 1}
local position = {0.5, 0.85}
local durationFrames = 60
local fadeFrames = 12

-- Justification mapping
local justificationMap = {
    ["Left"] = "Left",
    ["Center"] = "Center",
    ["Right"] = "Right"
}

-- === Helpers ===

function decodeMultiline(str)
    return str:gsub("\\n", "\n")
end

function trim(s)
    return s and s:match("^%s*(.-)%s*$") or nil
end

-- === CSV PARSER ===

function parseCSV(file)
    local titles = {}
    for line in io.lines(file) do
        -- Match 5 columns: timecode,"text",justification,font,fontSize
        local timecode, text, justify, font, size = line:match('^([^,]+),"(.-)",?([^,]*),?([^,]*),?([^,]*)$')
        if timecode and text then
            table.insert(titles, {
                timecode = trim(timecode),
                text = decodeMultiline(trim(text)),
                justify = justificationMap[trim(justify or "")] or "Center",
                font = trim(font) ~= "" and trim(font) or defaultFont,
                fontSize = tonumber(trim(size)) or defaultFontSize
            })
        end
    end
    return titles
end

-- === ADD TITLE CLIP ===

function addStyledTitle(timeline, item)
    local fps = tonumber(timeline:GetSetting("timelineFrameRate"))
    local startFrame = timeline:TimecodeToFrame(item.timecode)

    local titleClip = timeline:AddFusionTitleClip("Text+", 1, startFrame, durationFrames)

    if titleClip then
        titleClip:SetProperty("StyledText", item.text)
        titleClip:SetProperty("Font", item.font)
        titleClip:SetProperty("FontSize", item.fontSize)
        titleClip:SetProperty("ColorRed", color[1])
        titleClip:SetProperty("ColorGreen", color[2])
        titleClip:SetProperty("ColorBlue", color[3])
        titleClip:SetProperty("ColorAlpha", color[4])
        titleClip:SetProperty("PositionX", position[1])
        titleClip:SetProperty("PositionY", position[2])
        titleClip:SetProperty("HorizontalJustification", item.justify)

        -- Fade animation
        local fusionComp = titleClip:GetFusionCompByIndex(1)
        if fusionComp then
            local textNode = fusionComp:FindTool("Text1")
            if textNode then
                local opacity = textNode.StyledText:FindModifier("Opacity") or textNode:AddModifier("Opacity", "BezierSpline")
                if opacity then
                    local fadeInStart = 0
                    local fadeInEnd = fadeFrames
                    local fadeOutStart = durationFrames - fadeFrames
                    local fadeOutEnd = durationFrames

                    opacity[fadeInStart] = 0
                    opacity[fadeInEnd] = 1
                    opacity[fadeOutStart] = 1
                    opacity[fadeOutEnd] = 0
                end
            end
        end

        print(string.format("Added: \"%s\" at %s | %s | %s @ %.2f",
            item.text:gsub("\n", " / "),
            item.timecode,
            item.justify,
            item.font,
            item.fontSize))
    else
        print("Failed to add title at:", item.timecode)
    end
end

-- === MAIN ===

local titles = parseCSV(csvPath)

for _, entry in ipairs(titles) do
    addStyledTitle(tl, entry)
end

Offline
User avatar

KrunoSmithy

  • Posts: 4586
  • Joined: Fri Oct 20, 2023 11:01 pm
  • Real Name: Kruno Stifter

Re: help troubleshooting Lua script to import Titles from CS

PostFri Jun 13, 2025 6:14 pm

Have you tried Vonk Ultra Nodes?

https://www.steakunderwater.com/wesuckl ... php?t=5412

sshot-1352.jpg
sshot-1352.jpg (189.38 KiB) Viewed 361 times
Offline
User avatar

spinhead

  • Posts: 11
  • Joined: Sun Mar 01, 2020 6:39 pm
  • Location: PHX AZ
  • Real Name: Joel D Canfield

Re: help troubleshooting Lua script to import Titles from CS

PostFri Jun 13, 2025 6:23 pm

Never heard of it. Can't even figure out what it is from that link. Can't see how it's easier and more straightforward than writing a script and running it.
Offline
User avatar

KrunoSmithy

  • Posts: 4586
  • Joined: Fri Oct 20, 2023 11:01 pm
  • Real Name: Kruno Stifter

Re: help troubleshooting Lua script to import Titles from CS

PostFri Jun 13, 2025 6:50 pm

spinhead wrote:Never heard of it. Can't even figure out what it is from that link. Can't see how it's easier and more straightforward than writing a script and running it.


VonkUltra nodes are modifiers and data nodes that live in the flow and can be connected to by regular node. Use them via connect to... menu. Similar to publish/connect too.... workflow.

They are essentially modifiers for existing parameter that replace a lot of expressions and scripts you would have to write each time in the the nodes. And generally a lot easier than writing a script and running it because someone has already not only wrote the scripts and expressions but also build as interface and nodes so they can be chained to build more complex modifiers and data nodes. Categorized for your connivance. A lot easier than writing it all on your own from scratch, even with your buddy ChatGPT. And trying to debug half of stuff that won't work.

I know nothing about scripting. Used three VonkUltra nodes. And done. I suggest you explore them.
Offline
User avatar

spinhead

  • Posts: 11
  • Joined: Sun Mar 01, 2020 6:39 pm
  • Location: PHX AZ
  • Real Name: Joel D Canfield

Re: help troubleshooting Lua script to import Titles from CS

PostFri Jun 13, 2025 7:52 pm

If this tool can do what I'm asking, please explicitly show me how to use it.

If you can't help with my question please stop posting.
Offline
User avatar

KrunoSmithy

  • Posts: 4586
  • Joined: Fri Oct 20, 2023 11:01 pm
  • Real Name: Kruno Stifter

Re: help troubleshooting Lua script to import Titles from CS

PostFri Jun 13, 2025 8:14 pm

spinhead wrote:If this tool can do what I'm asking, please explicitly show me how to use it.
If you can't help with my question please stop posting.


Well, I sure won't help someone with that attitude. Jeez. Who raised you? Your are on your own, dude.
Offline
User avatar

spinhead

  • Posts: 11
  • Joined: Sun Mar 01, 2020 6:39 pm
  • Location: PHX AZ
  • Real Name: Joel D Canfield

Re: help troubleshooting Lua script to import Titles from CS

PostSun Jun 15, 2025 5:14 am

In case anyone else stumbles across this looking for help sorting out a Lua script for Davinci, the information in the DaVinci installation folders under Developer / Scripting looks helpful, between the API info in README.txt and the Examples folder.

Took a couple days of digging to discover that this information even existed. H'ray.

Return to DaVinci Resolve

Who is online

Users browsing this forum: DronePilot1977, marcoos, PhotoJoseph, Sami Sanpakkila, undefONE, VMFXBV and 435 guests