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


Ben Katz
Re: Getting different line width in same text box
on May 17, 2018 at 5:34:56 am

Hi, I'm trying to reproduce exactly that, but its not working, can you guys please explain a little more or give an example?

Thanks
Ben


Return to posts index

Andrew McClure
Re: Getting different line width in same text box
on Aug 2, 2018 at 9:39:47 pm

Hi Dan, thank you for this! Do you know if its possible for this to work without manually creating a line break?


Return to posts index

Dan Ebberts
Re: Getting different line width in same text box
on Aug 2, 2018 at 10:24:50 pm

I'm not sure what you mean. Are you talking about box text? If so, I can't think of anything.

Dan



Return to posts index


Kalleheikki Kannisto
Re: Getting different line width in same text box
on Aug 3, 2018 at 7:35:15 am

The only way you could achieve that, that I can think of, is having code that broke the paragraph text into lines first around a certain character count. The line breaks would be different from the automatic line breaks in paragraph text, but then you could utilize Dan's code to create the individual box widths. There are some existing threads on the subject of automatically adding line breaks at the space character around a given character count.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Andrew McClure
Re: Getting different line width in same text box
on Aug 3, 2018 at 10:54:07 am

This could work thank you so much Kalleheikki!


Return to posts index

Andrew McClure
Re: Getting different line width in same text box
on Aug 3, 2018 at 10:50:36 am

Hopefully this gif explains it better-



I'm trying to find a way for it to work without having to hit the enter key after each line


Return to posts index

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