ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

If last line empty - use previouse one

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kirill Komrakov
If last line empty - use previouse one
on Oct 15, 2019 at 8:02:08 am
Last Edited By Kirill Komrakov on Oct 15, 2019 at 8:08:21 am

Hey guys. I need some help figuring out how write it.

I have a bullet list with 9 lines of text.
What i am trying to write is an expression to find last line which is empty based on .height and use previous that is not empty.

I have an expression to determine the longest line.

var out_width = 0;
for (i = 1; i <= 9; i++) {
var elem = comp("T01 Text 0" + i).layer(1);
var w = elem.sourceRectAtTime(2).width;
if (out_width < w) out_width = w;
}

Found out similar question here
https://stackoverflow.com/questions/33268863/find-last-matching-object-in-a...

But can't figure out how to rework one i have to fit what i need.

Text lines naming goes like T01 Text 01, T01 Text 02 etc.
Can't use number of the layer, cause between lines of text can be other objects.

Thank you.


Return to posts index

Dan Ebberts
Re: If last line empty - use previouse one
on Oct 15, 2019 at 4:32:16 pm

I guess it would look something like this:


var maxNonEmpty = 0;
for (i = 1; i <= 9; i++) {
var elem = comp("T01 Text 0" + i).layer(1);
var w = elem.sourceRectAtTime(2).width;
if (w > 0){
maxNonEmpty = i;
}
}
maxNonEmpty



Dan



Return to posts index

Kirill Komrakov
Re: If last line empty - use previouse one
on Oct 16, 2019 at 7:18:09 pm

Thank you Dan! Worked like a charm!


Return to posts index


Kirill Komrakov
Re: If last line empty - use previouse one
on Oct 17, 2019 at 11:03:30 am

Dan, one more question.

This whole thing works perfectly with file names T01 Text 01 - T01 Text 09. When i want to add more text lines with names T01 Text 10 and etc. it results with an error, cause there is no comps like T01 Text 010. How should i change the conditions so i can use more lines of text with similar naming?

Thanks!


Return to posts index

Dan Ebberts
Re: If last line empty - use previouse one
on Oct 17, 2019 at 1:31:31 pm

I haven't tested this, so watch for typos, but something like this should work up to 99:


function pad(n){
return (n < 10 ? "0" : "") + n;
}
var maxNonEmpty = 0;
for (i = 1; i <= 15; i++) {
var elem = comp("T01 Text " + pad(i)).layer(1);
var w = elem.sourceRectAtTime(2).width;
if (w > 0){
maxNonEmpty = i;
}
}
maxNonEmpty



Dan



Return to posts index

Kirill Komrakov
Re: If last line empty - use previouse one
on Oct 17, 2019 at 2:23:43 pm

One day i hope i will learn this stufff too...

Thank you, everything works perfectly!


Return to posts index

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