Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: HomeForumBasicsExpressionsTutorialsPodcastsMotion GraphicsTrainingCinema 4DFAQ

Counter expression, split digits

Cow Forums : Adobe After Effects Expressions

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>
Counter expression, split digits
by James Armstrong on Apr 22, 2009 at 4:42:56 pm

Hi,

I am trying to create a 9 digit counter where the numbers are not displayed altogether, but rather spread across the comp.

What I need is an expression that controls my text layers based on selected digits of a number (generated by slider).

Originally I used

val = effect(”Slider Control”)(”Slider”);
numDec = 0; // digits to right of decimal
numDigit = 2; // digits to left of decimal
if (val < 0) sign = "-" else sign = ""; s = Math.abs(val).toFixed(numDec); while (s.length < numDigit + numDec + 1) s = "0" + s; sign + s

from a post here somewhere, with an aim to simply creating masks around the appropriate digit on each text layer and spreading them about. However the client has chosen a non monospace font so the numbers were all wiggling about in and out of their masks as the numbers around them changed.

To this end, if I could get a single digit per text layer, its position would remain pretty static. Can somebody help (Dan?) thanks.

Respond to this post   •   Return to posts index

Re: Counter expression, split digits
by Trent Armstrong on Apr 22, 2009 at 5:53:56 pm

You'll have to use a Text Layer for this. The Numbers Effect doesn't work.

You will probably have to use a separate layer for each number, but the technique should work.

Use "String()" to change your number to a string and then you "myNumber.substring()" to pick which value you want to display for that layer.

Trent Armstrong - Creative Cow Leader
http://www.dallasaeug.com

Respond to this post   •   Return to posts index

Re: Counter expression, split digits
by Dan Ebberts on Apr 22, 2009 at 5:44:33 pm

Assuming your digit layers are layer 1 thru 9 (with layer 1 being the left-most digit) this mod to your expression should get you close:

val = effect(”Slider Control”)(”Slider”);
numDec = 0; // digits to right of decimal
numDigit = 2; // digits to left of decimal
if (val < 0) sign = "-" else sign = "";
s = Math.abs(val).toFixed(numDec);
while (s.length < numDigit + numDec + 1) s = "0" + s;
s = sign + s;
s.substr(index-1,1)

Dan



Respond to this post   •   Return to posts index


Re: Counter expression, split digits
by Trent Armstrong on Apr 22, 2009 at 9:41:20 pm

As always, Dan is very elegant with his expressions.

Trent Armstrong - Creative Cow Leader
http://www.dallasaeug.com

Respond to this post   •   Return to posts index

Re: Counter expression, split digits
by damir gamulin on Apr 23, 2009 at 7:07:12 am

Hello, could this be done for longer text also?
If one would animate letters of a sentence and not digits ?

. . . . . .
g

Respond to this post   •   Return to posts index

Re: Counter expression, split digits
by James Armstrong on Apr 23, 2009 at 9:37:03 am

Wow! I didn't expect to get a response so fast! Thanks.

I tried Dan's expression out and came very close.

The problem I had was that in figures with less digits than the number of layers, the digits are appearing in the wrong place.

for instance if the slider was '1065' the text layers said '1065_ _ _ _ _ 'rather than' _ _ _ _ _ 1065'
So I just adjusted the digits to the left of the decimal place like so

val = thisComp.layer("Number Cruncher").effect("LAST6 digits")("Slider");
numDec = 0; // digits to right of decimal
numDigit = 8; // digits to left of decimal
if (val < 0) sign = "-" else sign = "";
s = Math.abs(val).toFixed(numDec);
while (s.length < numDigit + numDec + 1) s = "0" + s;
s = sign + s;
s.substr(index-1,1)

...and Robert's your mother's brother!

Now because the slider does not have enough digits to go up to numbers I need to show, I will create 2 pre comps controlled by 2 sliders in the main comp; one for the first 3 digits, one for the last 6.

So far so good, and thanks again!

Respond to this post   •   Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINETRAININGVIDEOS - REELSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]