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.
Step-by-Step Guide to Creating a Countdown in Fusion
Setting Up a New Fusion Composition
- Create a New Fusion Composition:
- Start by opening
Da Vinci Resolve
and creating a new Fusion composition.
- Start by opening
- Add a Text Node:
- Add a
Text
node and connect it toMediaOut1
.
- Add a
Configuring Custom Controls
- Edit Text Node Controls:
- Right-click on the
Text
node and select Edit Controls... from the context menu. - In the Edit Controls dialog, set up your custom control as shown below:
- Right-click on the
- Accessing the New Control:
- Your new control appears at the bottom of the
Text
node properties. It functions similarly to the Slider Controller in After Effects.
- Your new control appears at the bottom of the
Writing Expressions for Automation
- Adding an Expression to the Text Box:
- Right-click on the
text box
and select Expression from the context menu.
- Right-click on the
- Linking the Slider Value to Text:
- Write an expression to reference the
Slider
value inside the textbox:- The format is to use the
variable name
within theText()
function.
- The format is to use the
- Write an expression to reference the
Animating the Counter
- Animating the Counter Number:
- Adjust and animate the
Counter_Number
value. You will notice the number updating dynamically.
- Adjust and animate the
- Modifying the Number Format:
- To remove floating point numbers, open the Edit Control and configure it accordingly.
- Integer Number Animation:
- After adjusting, animate the control again, and the floating point issue will be resolved.
Advanced Countdown Scripting
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.
For Bangla Number Counter (Example- BDT 15,45,100)
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 .. '/-'
Line-by-Line Code Explaination
: -- Setup
- Colon (
:
): 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 = ","
- Defines a variable
thousandsSeperator
and assigns it a comma (,
) as a string. This is used later to insert commas for thousands separation.
prefix = "$"
- Defines a
prefix
variable containing the dollar sign ($
). It will be added to the start of the formatted number to represent currency.
suffix = ""
- Initializes a
suffix
variable as an empty string. This can be customized to add any characters you want to append to the number.
-- Setup end
- Another comment indicating the end of the setup section.
number = Counter_Number
- This assigns the value of
Counter_Number
(a variable or animated control in Fusion) to a local variablenumber
. This number is what we’ll format.
delimited = (string.format('%d', number)):reverse():gsub("(%d%d%d)", "%1" .. thousandsSeperator):gsub(",(%-?)$", "%1"):reverse()
- Detailed Breakdown:
string.format('%d', number)
: Convertsnumber
into a formatted string without decimal places.:reverse()
: Reverses the string to make inserting commas easier.:gsub("(%d%d%d)", "%1" .. thousandsSeperator)
: Uses Lua’sgsub
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)
- Combines
prefix
, the formatteddelimited
string, andsuffix
into the final output. This is the formatted text displayed in Da Vinci Resolve Fusion.
Final Note
- The colon (
:
) 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. - This script is ideal for creating a formatted and animated number display, with options to customize separators, prefixes, and suffixes.
There is a chance that you might face issues with BDT(৳) Font Issue
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 |