Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Counter expression, split digits

  • Counter expression, split digits

    Posted by James Armstrong on April 22, 2009 at 4:42 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.

    sage paddock reid replied 4 years, 5 months ago 5 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    April 22, 2009 at 5:44 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

  • Trent Armstrong

    April 22, 2009 at 5:53 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
    https://www.dallasaeug.com

  • Trent Armstrong

    April 22, 2009 at 9:41 pm

    As always, Dan is very elegant with his expressions.

    Trent Armstrong – Creative Cow Leader
    https://www.dallasaeug.com

  • Damir Gamulin

    April 23, 2009 at 7:07 am

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

    . . . . . .
    g

  • James Armstrong

    April 23, 2009 at 9:37 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!

  • sage paddock reid

    March 9, 2022 at 12:51 pm

    This is beautiful thank you! Helped me out a lot, im curious what the comma and second number does in

    “(index-1,1)”

    thanks!

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