• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Underline text - Expression Hell

Explorer ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

Hello,

Since Adobe after effects doesn't have an underline effect for fonts, and we all are tired of asking Adobe for it, I always have this requirements with my clients while doing my motion graphics of having text underlined. 

 

I found a video on YouTube on expressions on how to do it. I'll share that here :-

 

https://youtu.be/vRSvUN-iFmw?si=y8BDuTmOqP0sNTkJ

 

I wanna achive this exact thing. But here's my requirement. When I go to the next line on my text later this shape layer expression doesn't work. And for some reason the shape layer was sticking to the top end of the text later or on the bottom end of the text layer. I realised it was because of the anchor point of the text layer. But when I reset the anchor point to the middle of the text layer it didn't still work like an "Underline" effect. I know I can do multiple text layers and have multiple stroke layers and just animated the trim path as required. But it's not optimised. I wanted to know if we can like do some expression workaround where I can just keep typing and even if I press "Enter" and go to the next line the shape layer will adjust. I'll upload my file that I did. Anyone has ever tried this before. I would love to get some ideas. 

 

 

TOPICS
Expressions , How to

Views

173

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 18, 2024 Dec 18, 2024

Using an expression tied to a text animator for opacity to reveal an underline will not work unless you use a monospaced font, as the letters will not be the same width. If you use a monospaced font, you can tie trim paths directly to the start or end property of the opacity text animator. You should not tie it to the Offset property. 

 

For other text animators, the workflow depends entirely on the property you are animating, and it could also be tied to time. It all depends on the specific des

...

Votes

Translate

Translate
Community Expert ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

The author of that very short and unexplained tutorial left off compensation for the anchor point. All you have to do is subtract the Anchor Point. I almost always leave off "var" to reduce the typing and simplify the look of the expression. It also makes it easier to read and troubleshoot.

 

When referencing a layer above, instead of using the layer name, you can use index-1. This will make saving the shape layer underline as an animation preset work with any text layer.

 

Here is my simplified expression for position:

ref = thisComp.layer(index - 1);
p = ref.position;
a = ref.anchorPoint;
refBox = ref.sourceRectAtTime();
pad = 10;  // Distance between text and underline

x = p[0] - a[0]+ refBox.left + refBox.width / 2;
y = p[1] - a[1] + refBox.top + refBox.height + pad;

[x, y]

Here's the simplified expression for the rectangle size:

ref = thisComp.layer(index-1);
w = ref.sourceRectAtTime().width;
h = 5; // rectangle height
[w, h]

 My animation preset also includes a slider for the underline spacing, underline size, color control, and scale compensation. If I have a text layer that needs underlining, all I have to do is double-click the animation preset, and a shape layer is created that is accurately positioned, matches the text color, and follows the layer anywhere in the comp.

 

You can also compensate for text animators. 

 

I hope this helps.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

Underlining text using sourceRectAtTime() can get tripped up when the text has descenders. There are a couple of ways to deal with this, such as assuming the "x height" is half the font size, or, you can add an expression like this to the source text for your text layer:

 

time < 0 ? "x" : value

 

which sets the text to a single "x" character at times less than 0. You can then calcualte the line's position based on the height of the "x" but the width of the text. This modified position expression assumes the anchor point is in the center:

 

ref = thisComp.layer(index - 1);
pad = 10;
rW = ref.sourceRectAtTime(time,false);
rH = ref.sourceRectAtTime(-1,false);
ref.toComp([rW.left + rW.width/2, rH.top + rH.height]) + [0,pad]

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

Calculating the height of an "x" is brilliant. Thanks, Dan. I will add that option next time I dig into my text animation presets.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

Hello,

OMG this worked super amazingly. But my requirements were slightly different. I mean this still works. But now when I animated the text layer using text animator, opacity the shape layer still remains. I understand that even with the opacity animator the text layer is still there. Just sort of hidden. So since the expression is calculating the width of the text layer, the shape layer is there. So how do I make it animate using the same expression. So that I can animate the text layer opacity animator and it will work together with the shape layer. 

 

Secondly my requirement of having the underline effect on multiple lines on the same text layer still stands. Your expression worked, but when I press enter and add a next line the shape layer goes below the second line. I want the shape layer to be there for every line on the same text layer. Is that possible ? 

 

I'm uploading my file that I've done with trim paths as well. Please do check. But that way is not optimised. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

Using an expression tied to a text animator for opacity to reveal an underline will not work unless you use a monospaced font, as the letters will not be the same width. If you use a monospaced font, you can tie trim paths directly to the start or end property of the opacity text animator. You should not tie it to the Offset property. 

 

For other text animators, the workflow depends entirely on the property you are animating, and it could also be tied to time. It all depends on the specific design of the animation. 

 

The only real option is to use a simple track matte to reveal both the text layer and the underline. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 27, 2024 Dec 27, 2024

Copy link to clipboard

Copied

LATEST

Yeah. I understand. Thanks. I'll use a track matte to reveal it. It worked out much easier than I thought. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines