Jump to: Board index » General » Fusion

Can you use an expression to change text+ font?

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

ResolveNoob

  • Posts: 85
  • Joined: Wed Jul 31, 2019 1:42 pm
  • Real Name: Tumelo Mogale

Can you use an expression to change text+ font?

PostFri May 26, 2023 2:51 am

There are a few tutorials that try to recreate the Loki TV show opening sequence and I think it's an interesting challenge. In the sequence, each of the letters change font every 10 frames for a total of 36 times.

One way to do it is to keyframe the font change but is that's 144 keyframes. Is there a way to write an expression that changes the text+ font to a random font every x amount of frames?
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Can you use an expression to change text+ font?

PostFri May 26, 2023 6:34 am

Sounds like a task for a script, not an expression.
The caveat is, creating this single-use script might take more time than manually configuring the keyframes.
A script, or a macro for that matter, will prove useful if you need a template for reuse with diverse parameters.
Perhaps there's a fuse or a reactor effect that someone previously created, but I'm not aware of one.
You might consider searching the wesuckless forum for these types of tools.
Offline

ResolveNoob

  • Posts: 85
  • Joined: Wed Jul 31, 2019 1:42 pm
  • Real Name: Tumelo Mogale

Re: Can you use an expression to change text+ font?

PostFri May 26, 2023 9:28 am

iddos-l wrote:Sounds like a task for a script, not an expression.
The caveat is, creating this single-use script might take more time than manually configuring the keyframes.
A script, or a macro for that matter, will prove useful if you need a template for reuse with diverse parameters.
Perhaps there's a fuse or a reactor effect that someone previously created, but I'm not aware of one.
You might consider searching the wesuckless forum for these types of tools.


Thanks for the response. What makes you confident that it can not be done with an expression? In my mind, there are a few answers that would clarify it for me.
1. how do you refer to and set the font property in an expression?
2. does the text font property have an index where you can refer to a font using a numerical value or can you only refer to it by name?

If you could refer to it by index then you could do a mathematical randomize function.
Offline

Sander de Regt

  • Posts: 3500
  • Joined: Thu Nov 13, 2014 10:09 pm

Re: Can you use an expression to change text+ font?

PostFri May 26, 2023 10:16 am

These are interesting questions. I believe (but I'm not sure) that you can only refer to the name of the font. If it was index based then a comp on a computer with 10 fonts installed would render differently from a computer with 200 fonts installed. Fusion has to find the font that it needs, so it looks for the name.

I have no experience in scripting, so I can only talk in pseudocode. You might be able to extract the current font list and put that in an arry of sorts which you can then index and reorder to achieve what you want, but I don't know if this is actually possible.
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline

Frank Engel

  • Posts: 912
  • Joined: Thu May 17, 2018 11:09 pm
  • Real Name: Frank Engel

Re: Can you use an expression to change text+ font?

PostMon May 29, 2023 11:22 am

You are probably better off creating a separate text object for each letter in each font then animating the visibility of the individual objects.
Offline

ResolveNoob

  • Posts: 85
  • Joined: Wed Jul 31, 2019 1:42 pm
  • Real Name: Tumelo Mogale

Re: Can you use an expression to change text+ font?

PostMon May 29, 2023 4:16 pm

Sander de Regt wrote:These are interesting questions. I believe (but I'm not sure) that you can only refer to the name of the font. If it was index based then a comp on a computer with 10 fonts installed would render differently from a computer with 200 fonts installed. Fusion has to find the font that it needs, so it looks for the name.

I have no experience in scripting, so I can only talk in pseudocode. You might be able to extract the current font list and put that in an arry of sorts which you can then index and reorder to achieve what you want, but I don't know if this is actually possible.


You make a good point about the fonts. I have the same thought with regards to the pseudocode. I wish there was a comprehensive tutorial on scripting in resolve on Windows. I have once tried and sadly failed.
Offline

ResolveNoob

  • Posts: 85
  • Joined: Wed Jul 31, 2019 1:42 pm
  • Real Name: Tumelo Mogale

Re: Can you use an expression to change text+ font?

PostMon May 29, 2023 4:17 pm

Frank Engel wrote:You are probably better off creating a separate text object for each letter in each font then animating the visibility of the individual objects.


The keyframing method will definitely work. I just thought maybe someone here knew a more efficient way.
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Can you use an expression to change text+ font?

PostMon May 29, 2023 4:47 pm

Well, it's possible, but I have my doubts about more efficient. Here's an example:

Code: Select all
{
   Tools = ordered() {
      Text1_1 = TextPlus {
         CtrlWZoom = false,
         Inputs = {
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            LayoutRotation = Input { Value = 1, },
            TransformRotation = Input { Value = 1, },
            Softness1 = Input { Value = 1, },
            StyledText = Input { Value = "Fusion", },
            Font = Input {
               Value = "Symbola",
               Expression = ":fontlist = {[1] = \"Open Sans\", [2] = \"Arial\", [3] = \"Courier New\", [4] = \"Papyrus\", [5] = \"Symbola\"}; index = FontPicker; return Text(fontlist[index])",
            },
            Style = Input { Value = "Regular", },
            VerticalJustificationNew = Input { Value = 3, },
            HorizontalJustificationNew = Input { Value = 3, },
            FontPicker = Input { Value = 5, },
         },
         ViewInfo = OperatorInfo { Pos = { 452, 20.0909 } },
         UserControls = ordered() {
            FontPicker = {
               INP_MaxAllowed = 5,
               INP_Integer = true,
               INPID_InputControl = "SliderControl",
               INP_Default = 1,
               INP_MinScale = 1,
               INP_MinAllowed = 1,
               LINKID_DataType = "Number",
               ICS_ControlPage = "Text",
               LINKS_Name = "Font Picker",
            }
         }
      }
   }
}


Part of the problem is that when you set an expression on the Font control, it doesn't display an expression box. But the expression is still there! You have to open a text editor to modify it.

First, you need to enable the multi-statement expression mode by starting the expression with a colon :
In this mode, you write the expression without line-breaks, but end each statement with a semi-colon ;
Also, you have to use an explicit "return" statement to send the results back to the control.

I enclosed the thing in double brackets [[ ]], which turns a string into a string literal, meaning all of the characters are treated as what they are instead of allowing any magic characters to do their thing. That removes the need to escape the quote marks with backslashes. The ordered table fontlist maps integers to font names, so the FontPicker control can choose from the list.

Take note that not every font has the same styles available; I set that input to "Regular" so the fonts I chose would all render without needing to futz with it.
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com
Offline

ResolveNoob

  • Posts: 85
  • Joined: Wed Jul 31, 2019 1:42 pm
  • Real Name: Tumelo Mogale

Re: Can you use an expression to change text+ font?

PostMon May 29, 2023 8:34 pm

Bryan Ray wrote:Well, it's possible, but I have my doubts about more efficient. Here's an example:

Code: Select all
{
   Tools = ordered() {
      Text1_1 = TextPlus {
         CtrlWZoom = false,
         Inputs = {
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            LayoutRotation = Input { Value = 1, },
            TransformRotation = Input { Value = 1, },
            Softness1 = Input { Value = 1, },
            StyledText = Input { Value = "Fusion", },
            Font = Input {
               Value = "Symbola",
               Expression = ":fontlist = {[1] = \"Open Sans\", [2] = \"Arial\", [3] = \"Courier New\", [4] = \"Papyrus\", [5] = \"Symbola\"}; index = FontPicker; return Text(fontlist[index])",
            },
            Style = Input { Value = "Regular", },
            VerticalJustificationNew = Input { Value = 3, },
            HorizontalJustificationNew = Input { Value = 3, },
            FontPicker = Input { Value = 5, },
         },
         ViewInfo = OperatorInfo { Pos = { 452, 20.0909 } },
         UserControls = ordered() {
            FontPicker = {
               INP_MaxAllowed = 5,
               INP_Integer = true,
               INPID_InputControl = "SliderControl",
               INP_Default = 1,
               INP_MinScale = 1,
               INP_MinAllowed = 1,
               LINKID_DataType = "Number",
               ICS_ControlPage = "Text",
               LINKS_Name = "Font Picker",
            }
         }
      }
   }
}


Part of the problem is that when you set an expression on the Font control, it doesn't display an expression box. But the expression is still there! You have to open a text editor to modify it.

First, you need to enable the multi-statement expression mode by starting the expression with a colon :
In this mode, you write the expression without line-breaks, but end each statement with a semi-colon ;
Also, you have to use an explicit "return" statement to send the results back to the control.

I enclosed the thing in double brackets [[ ]], which turns a string into a string literal, meaning all of the characters are treated as what they are instead of allowing any magic characters to do their thing. That removes the need to escape the quote marks with backslashes. The ordered table fontlist maps integers to font names, so the FontPicker control can choose from the list.

Take note that not every font has the same styles available; I set that input to "Regular" so the fonts I chose would all render without needing to futz with it.



Thanks so much Bryan. It works. I see you created a font picker slider control and I was able to add a further expression to that to do the random selection.

I can see how it would be less efficient than keyframing if you have to write each font out by name. I guess it's only more efficient if there was a function to get all the fonts automatically, already sorted in an array. If not already in an array, maybe another function to assign the fonts to an array as Sander suggested. Thanks for the help though.

The question I have is how do you access the text editor where you can write the expression?
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Can you use an expression to change text+ font?

PostTue May 30, 2023 7:40 pm

Copy the node with Ctrl+C and then paste into a programmer's text editor like Notepad++ or Sublime or the like (those are the Windows options; I don't recall off the top of my head what the options are in other OS's). When you're ready to test, copy the text and paste it back into the node view.

If you ever get into building macros, you'll likely find yourself doing that quite a bit because it's way easier to edit a macro that way than using the UI once you learn how.

edit: Bah! I just noticed that Fusion removed my lovely double brackets and escaped all of the quote marks instead. Here it is the way I originally formatted it:

Code: Select all
{
   Tools = ordered() {
      Text1 = TextPlus {
         CtrlWZoom = false,
         Inputs = {
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            LayoutRotation = Input { Value = 1, },
            TransformRotation = Input { Value = 1, },
            Softness1 = Input { Value = 1, },
            Font = Input {
               Value = "Open Sans",
               Expression = [[:fontlist = {[1] = "Open Sans", [2] = "Arial", [3] = "Courier New", [4] = "Papyrus", [5] = "Symbola"}; index = FontPicker; return Text(fontlist[index])]]
            },
            Style = Input { Value = "Regular", },
            VerticalJustificationNew = Input { Value = 3, },
            HorizontalJustificationNew = Input { Value = 3, },
         },
         ViewInfo = OperatorInfo { Pos = { 739, 94.6818 } },
         UserControls = ordered() {
            FontPicker = {
               LINKS_Name = "Font Picker",
               LINKID_DataType = "Number",
               INPID_InputControl = "SliderControl",
               INP_Default = 1,
               INP_Integer = true,
               INP_MinAllowed = 1,
               INP_MaxAllowed = 5,
               ICS_ControlPage = "Text",
               INP_MinScale = 1,
            }
         }
      }
   },
   ActiveTool = "Text1"
}
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com

Return to Fusion

Who is online

Users browsing this forum: No registered users and 37 guests