Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Increment and add numbers in a text layer

  • Increment and add numbers in a text layer

  • Omar Reyes

    March 26, 2020 at 9:23 pm

    I have a text layer that has lines with some text and a number at the end followed by a comma. I’m trying to find a way to add all the numbers together and put that value on another text layer.

    For example the source text layer looks like this:

    sample line 7,
    apple 1,
    bees 14,
    USA 56,
    other line 106,
    etc… 45,

    I’m using this in the total text layer to get the number in a line:
    v1=thisComp.layer(“Sample Layer”).text.sourceText.split(“,”)[0].slice(-3);

    Rather than making variables v1, v2, v3, v4, v5, v6, and so on, I’m wondering if there’s a way to use the i loop script or something to generate a list of just the numbers and then add them? The list will have a either 53, 66 or 87 lines.

  • Andrei Popa

    March 27, 2020 at 1:17 am

    var str = thisComp.layer("Sample Layer").text.sourceText.match(/\d+/g);
    eval(str.join("+"))

    Andrei
    My Envato portfolio.

  • Omar Reyes

    March 27, 2020 at 4:26 pm

    Didn’t think it would be that simple, thank you!

Viewing 1 - 3 of 3 posts

Log in to reply.

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