Skip to main content
Participant
June 6, 2023
Answered

Issue with Font Style Change and Animation in After Effects Expressions

  • June 6, 2023
  • 2 replies
  • 340 views

 

Hello everyone,

I'm encountering a problem in After Effects, and I'm hoping to get some assistance from the community. I have a composition where I want to preserve the animation of a text layer (LineOne) while ensuring that another text layer (LineOneUnderscore) always maintains the same style, including font size and font family, as LineOne.

I've written the following code in After Effects to achieve this:

 

jsxCopy code
var lineOne = thisComp.layer("LineOne"); var lineOneUnderscore = thisComp.layer("LineOne_Underscore"); // Get the source text from LineOne var s = ''; if (lineOne.text.sourceText.length > 0) { s = lineOne.text.sourceText; } // Take the same style as Layer one lineOneUnderscore.text.style = lineOne.text.sourceText.style; // Apply the source text from LineOne to LineOne_Underscore with an underscore character s + "_";
 

The issue I'm facing is that when I execute the line lineOneUnderscore.text.style = lineOne.text.sourceText.style;, the animation in LineOne is lost. On the other hand, if I place this line (s + "_"😉 at the bottom of the code, the animation works fine, but then the style synchronization doesn't occur.

 

If anyone has encountered a similar problem or has expertise in After Effects scripting, I would greatly appreciate your help. How can I modify the code to ensure that LineOneUnderscore always has the same style as LineOne, while preserving the animation effect?

Thank you in advance for any assistance you can provide!

This topic has been closed for replies.
Correct answer Dan Ebberts

Try it this way:

 

var lineOne = thisComp.layer("LineOne"); 
var lineOneUnderscore = thisComp.layer("LineOne_Underscore"); 
// Get the source text from LineOne 
var s = ''; 
if (lineOne.text.sourceText.length > 0) { s = lineOne.text.sourceText; } 
// Take the same style as Layer one 
var myStyle = lineOne.text.sourceText.style; 
// Apply the source text from LineOne to LineOne_Underscore with an underscore character 
myStyle.setText(s + "_");

 

2 replies

Mylenium
Legend
June 6, 2023

It's a limitation of how this stuff works. You have to split the text into separate layers if you really want to control it.

 

Mylenium

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
June 6, 2023

Try it this way:

 

var lineOne = thisComp.layer("LineOne"); 
var lineOneUnderscore = thisComp.layer("LineOne_Underscore"); 
// Get the source text from LineOne 
var s = ''; 
if (lineOne.text.sourceText.length > 0) { s = lineOne.text.sourceText; } 
// Take the same style as Layer one 
var myStyle = lineOne.text.sourceText.style; 
// Apply the source text from LineOne to LineOne_Underscore with an underscore character 
myStyle.setText(s + "_");

 

Participant
June 7, 2023

You are a hero Dan! Thanks a lot!

You make my day!

Have a sunny day!