ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Increment and add numbers in a text layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Omar Reyes
Increment and add numbers in a text layer
on Mar 26, 2020 at 9:23:28 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.


Return to posts index

Andrei Popa
Re: Increment and add numbers in a text layer
on Mar 27, 2020 at 1:17:42 am

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


Andrei
My Envato portfolio.


Return to posts index

Omar Reyes
Re: Increment and add numbers in a text layer
on Mar 27, 2020 at 4:26:52 pm

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


Return to posts index

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