ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Getting different line width in same text box

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Evelyn Zhang
Getting different line width in same text box
on Jun 23, 2017 at 8:41:34 pm

I'm trying a .sourceRectAtTime().width expression where the box shape is responsive to the length of the text —

x=thisComp.layer("Text on Screen").sourceRectAtTime().width;
y=70*1.4;
[x+100,y]


This code only returns the width of the entire text box, so the bar width are all the same. Does anyone have any idea on how to get the width of each individual line? without having to start different text box for every line? Thanks!!



Return to posts index

Dan Ebberts
Re: Getting different line width in same text box
on Jun 24, 2017 at 6:38:28 pm

This is definitely a hack of sorts, and I don't know how robust/reliable it is, but you could give it a try. You would put this expression in the source text of your text layer:


if (time < 0){
s = value.split("\r");
txt = ""
for (i = 0; i < s.length; i++){
if (time > -10*(i+1)){
txt = s[i];
break;
}
}
txt;
}else
value


For the rectangle for the first line of text, you'd get the width this way:

myLine = 1;
L = thisComp.layer("text");
w = L.sourceRectAtTime(-10*(myLine-1)-5).width

For the second line of text you'd change the first line of the expression to:

myLine = 2;

etc.

Dan



Return to posts index

Evelyn Zhang
Re: Getting different line width in same text box
on Jun 27, 2017 at 12:48:01 am

You, sir, are a literal angel. This is exactly what I need. THANK YOU SOOOO MUCH.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]