John Holt
114 supporters
The Power of Text+

The Power of Text+

Jul 27, 2021

Today we are talking about String Theory so we will be focusing on Text. I picked this subject as it is a very popular form of graphic in a project.

String Theory

Although I think the Text+ or Text1 node is the most powerful node in resolve, I am not going to go through all the controls. Think of this post as the bits everyone else seems to miss out on. (yes, I know there are exceptions). In no particular order, although I might have to build a title by the end of this post.

Typing! what's that all about?

I am better at copy & paste but we don't even have to bother with that as the Text+ or Text1 can read a txt file.

Currently, there is a caveat, which is I have only figured out how to do this using the default DaVinci Resolve Document folder. Yes, you have one it is in your document folder. You currently have to place the text document you want the Text+ to read in this folder. (from now on Text+ will include Text1).

The folder path on a PC is: C:\Documents\Blackmagic Design\DaVinci Resolve\Fusion

I use Notepad++ for this purpose as I can auto-format the text quickly. In this example, I am going to call my text document "text.txt"

Right-click inside the StyledText Box and select Expression, then paste the expression below into the expression box.

Text(assert(io.open(comp:MapPath("comp:/text.txt"), "r")):read("*all"):gsub("\\n", '\n'):gsub("\\t", " "))

This expression brings in the whole file as it is formatted in the text.txt file and is great if someone sends you "copy" to include in a project. You can render out your project, change the contents of the file and then render again with the different text.

There's also no reason not to have multiple txt documents and multiple Text+ with this expression and just change the file name.

Whilst I am on the subject of reading an external document, I shall continue with reading a list 1 line at a time at a set rate. However, this is not done in the StyledText Box it is setup on the settings page in both the "Frame Render Script" and "Start Render Script" This will read a list.txt from anywhere on your computer as long as you ensure the part of the code which points to the file is correct.

Frame Render Script

index = math.floor(time / interval)

if index > num_lines then

index = num_lines

end

StyledText = t[index]

Start Render Script

f = [[C:\list.txt]] -- The path to the file

interval = 2 -- The interval you want the text to change in frames

t = {}

for l in io.lines(f) do

table.insert(t, l)

end

num_lines = table.getn(t)

Next up we will look at some interesting text expressions.

The setup is you have a Text1 node and then copy and paste instance, so you have 2 text nodes. In the instance click inside the StyledText box right click and select deinstance.

You now have 2 identical text nodes apart from the StyledText Boxes are no longer connected. You may have to deinstance position if you want both text nodes to appear on the screen together.

Type something in Text1.

In instanceText1 right-click in the StyledText box and select Expression

I wonder how many characters are in the text you typed in Text1?

Enter the following expression in the instanceText1 expression box.

string.len(Text1.StyledText.Value)

If you entered more than 1 line of text in Text1, how many lines are there?

:_, mylines = string.gsub(Text1.StyledText.Value, "\n", ""); return mylines

No that social media isn't popular again, it returns the number of spaces

:_, myspaces = string.gsub(Text1.StyledText.Value, "%s", ""); return myspaces

Returns the number of letters(not including spaces)

:_, myletters = string.gsub(Text1.StyledText.Value, "%a", ""); return myletters

Returns number of lower case(numbers included)

:_, mylower = string.gsub(Text1.StyledText.Value, "%l", ""); return mylower

Returns the number of UPPER case characters

:_, myupper = string.gsub(Text1.StyledText.Value, "%u", ""); return myupper

Returns the number of alphanumeric

:_, alphanumeric = string.gsub(Text1.StyledText.Value, "%w", ""); return alphanumeric

Returns the number of vowels

:_, myvow = string.gsub(Text1.StyledText.Value, "[AEIOUaeiou]", ""); return myvow

Returns anything except vowels(includes spaces, controls & numbers)

:_, novow = string.gsub(Text1.StyledText.Value, "[^AEIOUaeiou]", ""); return novow

Returns the number of digits

:_, mydigits = string.gsub(Text1.StyledText.Value, "%d", ""); return mydigits

Returns the number of punctuations

:_, punctuation = string.gsub(Text1.StyledText.Value, "%p", ""); return punctuation

Returns the number of control characters

:_, controlchar = string.gsub(Text1.StyledText.Value, "%c", ""); return controlchar

Returns the number of hexadecimal digits(occasionally confused as spaces are invisible hexdeciamals)

:_, myhex = string.gsub(Text1.StyledText.Value, "%x", ""); return myhex

Changing the lower case letter after the % to an upper case, returns the compliment (opposite)

Returns how many non letters

:_, myletters = string.gsub(Text1.StyledText.Value, "%A", ""); return myletters

Adding the ^ (caret) before the % will return the number of everything except

Display The Text typed into Text1 in instanceText1 but repeat it 3 times.

string.rep(Text1.StyledText.Value, 3)

Display The Text typed into Text1 in instanceText1 but reverse it.

string.reverse(Text1.StyledText.Value)

Display The Text typed into Text1 in instanceText1 but all lower case.

string.lower(Text1.StyledText.Value)

Display The Text typed into Text1 in instanceText1 but all UPPER case.

string.upper(Text1.StyledText.Value)

Display the first 2 letters from the Text typed into Text1.

string.sub(Text1.StyledText.Value, 1, 2)

This is powerful as you can pull parts of the text. The whole number is from the left so 1,3 is displaying the 1st, 2nd & 3rd. Negative numbers from the right.

Display the ASCII code for a letter in Text+

string.byte(Text1.StyledText.Value, 1)

The whole number is from the left so 1 is displaying the 1st letter as a byte ASCII. Negative numbers from the right.

Display text from ASCII code

string.char(Text1.StyledText.Value, 1)

The whole number is from the left so 1 is displaying the 1st letter as a character from ASCII. Negative numbers from the right.

Displays The Text typed into Text1 and concatenates a space and then the word Eggs.

Text1.StyledText.Value .. " " .. "Eggs"

Concatenates 2 StyledText Fields

Text1.StyledText.Value .. Text2.StyledText.Value

You may have noticed that on the settings page of every node you have "Comments". Well, this is just another text box you can use and add modifiers and expressions to.

Concatenate Text1 StyledText with whatever you put in the comments box.

Text1.StyledText.Value .. Comments.Value

Text1.StyledText.Value .. " " .. Comments.Value

-- .. the 2 dots concatenate what is before them with what is after them, it is sometimes necessary to add a space so .. " " .. will do just that.

Here's a fun one right-click inside the comments and select time code and concatenate the Text1. StyledText with a time code or any other modifier.

Text1.StyledText.Value .. " " .. Comments.Value

How many times have you wanted to build out a scrolling end credit or a news ticker? Did you know that they are both built-in?

On a Text+ go to Layout Page and change Type from Point to Frame, for a scrolling text, on the layout page change the width and height to 1.

Go to the Text Page and look below the anchor controls, a combo box with the name scroll appeared. Still is well, still, Roll is scroll and crawl is news ticker.

Selecting roll will open another control called "Scroll Position" right-click on the word scroll position and select Expression. Enter the following expression to have a scrolling credit roll from bottom to top.

1-(time/comp.RenderEnd)

Ooh! don't forget to add some text in the StyledText Box.

Thought it was time for a picture

To have a news ticker change the scroll to crawl and play with the position as well as the width & height in the layout tab.

Obvious but not so obvious.

You can display any parameter from any node in a Text+ using the following expressions. NodeName.Control, so Transform1.Angle will display the Angle of Transform1

Displays the coordinates of the Text+

Center.X .. " " ..Center.Y

Display the Center X position to 4 decimal places.

string.format("%.4f" ,Center.X)

Display x and y coordinates to 2 decimal places

string.format("%.2f" ,Center.X) .. "x" .. " ".. string.format("%.2f" ,Center.Y) .. "y"

Generates a random number, this will go crazy when you press play as it will give you a random number every frame.

math.random()

Generates a random number between 0 and 100, this will go crazy when you press play as it will give you a random number every frame.

math.random(0, 100)

Displays the short day of the week, caution with the cache as this can cause issues with the os.date expression. however, it should render out okay.

os.date("%a")

%a abbreviated weekday name (e.g., Wed)

%A full weekday name (e.g., Wednesday)

%b abbreviated month name (e.g., Sep)

%B full month name (e.g., September)

%c date and time (e.g., 09/16/98 23:48:10)

%d day of the month (16) [01-31]

%H hour, using a 24-hour clock (23) [00-23]

%I hour, using a 12-hour clock (11) [01-12]

%M minute (48) [00-59]

%m month (09) [01-12]

%p either “am” or “pm” (pm)

%S second (10) [00-61

%w weekday (3) [0-6 = Sunday-Saturday]

%x date (e.g., 09/16/98)

%X time (e.g., 23:48:10)

%Y full year (1998)

%y two-digit year (98) [00-99]

%% the character `%´

So far we have covered what is possible in the StyledText box, let's move on to Fonts. What can we possibly do with Fonts?

I don't know about you but my Font list is huge and I only use a selected few, so let us make a Font favourite list. Open the DaVinci Resolve documents folder (could be anywhere but want to keep track of it). Create a folder called "Fonts" and add in your favourite Fonts.

The folder path on a PC is: C:\Documents\Blackmagic Design\DaVinci Resolve

Head to the Fusion Page inside DaVinci Resolve and open the Fusion > Fusion Settings > Path Map.

Select Fonts from the list and the details will appear at the bottom of the settings panel, click on the folder and navigate to your favourite fonts folder. Select save and restart resolve, this is because it loads the fonts on start-up. Done, you now have a favourites font drop-down in the Text+

Why is text always in a straight line? It doesn't have to be!

On the fusion page with some text on the screen and the text node selected, look in the top left of the viewer.

Hover over the icons and select "allow manual kerning", then zoom into your text on the screen. Spotted anything yet, well that small red square will allow you to reposition individual letters.

Maybe not a practical example

Apart from all the usual text controls that was some fun snippets, time for me to grab a coffee and then start decorating again.

Thanks for taking the time to read this post and if you would like to buy me a coffee, pizza, narrowboat then it is greatly appreciated.

https://www.buymeacoffee.com/mrjholt

Enjoy this post?

Buy John Holt a coffee

More from John Holt