How to Use Expressions in Da Vinci Resolve Fusion for Animation

Fusion Countdown Expression

Create a Countdown Timer in Da Vinci Resolve Fusion Using Expressions

fusion
expression
da vinci resolve
counter expression

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

  1. Create a New Fusion Composition:
    • Start by opening Da Vinci Resolve and creating a new Fusion composition.
  2. Add a Text Node:
    • Add a Text node and connect it to MediaOut1.

Configuring Custom Controls

  1. 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: Edit Control Configuration
  2. 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.

Writing Expressions for Automation

  1. Adding an Expression to the Text Box:
    • Right-click on the text box and select Expression from the context menu. Add Expression
  2. 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 the Text() function. Linking Expression

Animating the Counter

  1. Animating the Counter Number:
    • Adjust and animate the Counter_Number value. You will notice the number updating dynamically. Animating Controls
  2. Modifying the Number Format:
    • To remove floating point numbers, open the Edit Control and configure it accordingly. Activate Integer
  3. Integer Number Animation:
    • After adjusting, animate the control again, and the floating point issue will be resolved. Integer Number

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

  1. : -- 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.
  1. thousandsSeperator = ","
  • Defines a variable thousandsSeperator and assigns it a comma (,) as a string. This is used later to insert commas for thousands separation.
  1. prefix = "$"
  • Defines a prefix variable containing the dollar sign ($). It will be added to the start of the formatted number to represent currency.
  1. suffix = ""
  • Initializes a suffix variable as an empty string. This can be customized to add any characters you want to append to the number.
  1. -- Setup end
  • Another comment indicating the end of the setup section.
  1. number = Counter_Number
  • This assigns the value of Counter_Number (a variable or animated control in Fusion) to a local variable number. This number is what we’ll format.
  1. delimited = (string.format('%d', number)):reverse():gsub("(%d%d%d)", "%1" .. thousandsSeperator):gsub(",(%-?)$", "%1"):reverse()
  • Detailed Breakdown:
    • 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.
  1. return(prefix .. delimited .. suffix)
  • Combines prefix, the formatted delimited string, and suffix 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