How to Use Expressions in Da Vinci Resolve Fusion for Animation


Expressions are powerful tools that allow us to automate and link parameters within the compositions.
By using expressions, we can create dynamic relationships between different elements, automate animations, and perform complex calculations without manual keyframing
In this article we are going to learn how to use expressions in Da Vinci Resolve Fusion by creating a number Counter example.
Da Vinci Resolve and creating a new Fusion composition. Text node and connect it to MediaOut1. Text node and select Edit Controls... from the context menu.
Text node properties. It functions similarly to the Slider Controller in After Effects. text box and select Expression from the context menu.
Slider value inside the textbox:variable name within the Text() function.
Counter_Number value. You will notice the number updating dynamically.
Here is a Lua script you can use to count USD in Fusion
:-- Setup
thousandsSeperator = ","
prefix = "$"
suffix = ""
-- Setup end
-- Counter is a variable in Fusion, you have replace it with your custom control
number = Counter
delimited = (string.format('%d', number)):reverse():gsub("(%d%d%d)", "%1" .. thousandsSeperator):gsub(",(%-?)$", "%1"):reverse()
return(prefix .. delimited .. suffix)This script formats the
counter, adding commas for thousands separators and allows you to set a prefix or suffix.
In Bangla number system, thousands separators are not used. Commas are used differently, usually to separate groups in the lakh and crore numbering system.
The main difference is that in USD, commas separate every three digits, while in BDT, commas are placed in thousands, lakhs, crores.
Here is the lua script for BDT, example: 15,45,100: -- LUA Custom Functions -- function formatBDT (number) thousandsSeperator = "," formatted = tostring(number) formatted = formatted:reverse():gsub("(%d%d%d)", "%1" .. thousandsSeperator):gsub(",(%-?)$", "%1"):reverse() -- Compare the length of the formatted string if #formatted > 6 then formatted2 = formatted:gsub("(%d)", "%1,", 1) return formatted2 else return formatted end return formatted end; -- Counter is a variable in Fusion, you have replace it with your custom control number = Counter formattedNumber = formatBDT(number) return "$" .. formattedNumber .. '/-'
: -- Setup :): The colon at the beginning is critical in Da Vinci Resolve Fusion. It signals that the following block of code is a Lua script. Without the colon, Fusion treats the content as a standard text expression rather than executing it as a Lua script. -- Setup: This is a comment, which Lua ignores. It’s used to annotate the code for readability. thousandsSeperator = "," thousandsSeperator and assigns it a comma (,) as a string. This is used later to insert commas for thousands separation. prefix = "$" prefix variable containing the dollar sign ($). It will be added to the start of the formatted number to represent currency. suffix = "" suffix variable as an empty string. This can be customized to add any characters you want to append to the number. -- Setup end number = Counter_Number Counter_Number (a variable or animated control in Fusion) to a local variable number. This number is what we’ll format. delimited = (string.format('%d', number)):reverse():gsub("(%d%d%d)", "%1" .. thousandsSeperator):gsub(",(%-?)$", "%1"):reverse() string.format('%d', number): Converts number into a formatted string without decimal places. :reverse(): Reverses the string to make inserting commas easier. :gsub("(%d%d%d)", "%1" .. thousandsSeperator): Uses Lua’s gsub function to insert a comma after every group of three digits. :gsub(",(%-?)$", "%1"): Removes any trailing comma that could occur if the number perfectly ends on a thousand boundary. :reverse(): Reverses the string back to the correct order, now formatted with commas. return(prefix .. delimited .. suffix) prefix, the formatted delimited string, and suffix into the final output. This is the formatted text displayed in Da Vinci Resolve Fusion. :) at the beginning is essential. It tells Da Vinci Resolve Fusion to treat the expression as a Lua script. Without the colon, Fusion will not interpret the code correctly. Here are the font's where the BDT(৳) sign will work in Da Vinci Resolve Fusion
| BDT Symbol | Font |
|---|---|
| ৳ | Corbel |
| Ekushey Punarbhaba | |
| Kalpurush | |
| KongshoOMJ | |
| Microsoft Sans Serif | |
| MS Gothic | |
| MS PGothic | |
| MS UI Gothic | |
| Nirmala UI | |
| Sergoe UI | |
| Shorif Ador Unicode | |
| Shorif Bongobondhu UNICODE | |
| Siyam Rupali | |
| Toha Borno Unicode | |
| Uber Move Text | |
| Vrinda | |
| Yu Gothic |