Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If last line empty – use previouse one

  • If last line empty – use previouse one

    Posted by Kirill Komrakov on October 15, 2019 at 8:02 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-array-of-objects

    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.

    Kirill Komrakov replied 6 years, 10 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 15, 2019 at 4:32 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

  • Kirill Komrakov

    October 16, 2019 at 7:18 pm

    Thank you Dan! Worked like a charm!

  • Kirill Komrakov

    October 17, 2019 at 11:03 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!

  • Dan Ebberts

    October 17, 2019 at 1: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

  • Kirill Komrakov

    October 17, 2019 at 2:23 pm

    One day i hope i will learn this stufff too…

    Thank you, everything works perfectly!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy