r/davinciresolve • • 1d ago

Tutorial | English Dynamic Tool Name Update in Expression Scripts: The First Approach

Ladies and gentlemen, step right up! Tonight in DaVinci Fusion, our trapeze artist attempts a triple somersault—first without a net, and then with full OSHA compliance. 🎪

We all know the classic Fusion headache: you hardcode Text1.Output inside an expression, rename the node later or copy paste a set of nodes, and suddenly your entire comp goes up in flames. Since the expression scripts are not automatically updated by fusion you're normally stuck editing expressions by hand like a caveman.

Not today. Here is how to cheat the system in two acts.

Act 1: The Triple Somersault (No Net)

First, let's look at the raw trick to appreciate the sheer audacity of it:

  1. Hijack the Comments field: Enable expressions on your node's completely useless (most of the time) Comments field and type Text1.Name. Now Comments automatically tracks whatever you rename that node to.
  2. Let dostring do the dirty work: Since we can't look up nodes dynamically through normal APIs, we glue the string together and let Lua's vintage dostring resolve the symbol on the fly in your clever script:

Lua

:
newname = Comments.Value
im = dostring("return " .. newname .. ".Output")
dw = im.DataWindow
return (dw.left - dw.right) / im.Width

Pure, unadulterated acrobatics. Four lines, zero safety checks, and if you rename Text1 to Title_Final_v9_REAL, it doesn't even flinch.

Act 2: Putting the Safety Net Under the Trapeze

Of course, performing without a net is great until someone accidentally clears the Comments field, types an actual human note with spaces in it, or scrubs to a frame where the image isn't rendered yet, sending your node crashing to the floor in bright red.

So, before you ship this into a real comp, let's unroll the safety net:

Lua

:
local newname = (Comments and Comments.Value) and tostring(Comments.Value) or ""
if not newname:match("^[%a_][%w_]*$") then return 0 end

local ok, im = pcall(dostring, "return " .. newname .. ".Output")
if not ok or not im or not im.DataWindow or not im.Width or im.Width == 0 then
    return 0
end

local dw = im.DataWindow
return (dw.left - dw.right) / im.Width
  • The bouncer (match): Checks that Comments actually contains a valid Lua variable name (no spaces, no weird punctuation, no empty strings) before letting it anywhere near dostring.
  • The crash pad (pcall): Catches any unexpected misfires if the target node vanishes or hasn't evaluated yet, gracefully returning 0 instead of nuking your expression.
  • The sanity check: Makes sure im, DataWindow, and a non-zero Width actually exist before dividing by zero and opening a black hole in Fusion.

Unless your kids, your spouse, or your cat decide to "help" with your comp while you're grabbing a coffee, the no-net version is faster and gets the job done just fine.

This version works, but it's a bit power-consuming ( the dostring() is evaluated on each frame) Don't worry we can do more acrobatic exercise.

2 Upvotes

1 comment sorted by

1

u/cranky-donkey Studio 23h ago

Very nice. Thanks for the clear explanations.