Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Formatting text that has a counter expression applied? Paging Mr. Dan.

  • Formatting text that has a counter expression applied? Paging Mr. Dan.

    Posted by Eric Bowman on March 24, 2011 at 3:17 am

    So I’m using the following code from Dan Ebberts’s site, to animate text from 0 to $10,000,000:

    numDecimals = 0;
    commas = true;
    dollarSign = true;
    beginCount = 0;
    endCount = 10000000;
    dur = 4;

    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";

    if (commas){
    decimals = "";
    if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
    }
    outStr = s.substr(-s.length, (s.length-1)%3 +1);
    for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
    }
    prefix + outStr + decimals;
    }else{
    prefix + s;
    }

    It works incredibly well, but I need to style the text.

    1) I need the dollar sign to be a smaller size and need to control it’s baseline shift.

    2) The commas need to be a smaller size than the rest of the numbers.

    3) The vertical scale of the entire chunk of text needs to be greater than 100% for the numbers but nothing else.

    Any ideas?

    Eric Bowman

    Eric Bowman replied 15 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 24, 2011 at 4:41 am

    You could try using three separate animators. For each animator you would add an expression selector, delete the range selector and add an expression to the expression selector amount property.

    For the smaller dollar sign and commas, use a scale animator (scale set to 60,60 say) with this expression:

    txt = text.sourceText;
    if (txt[textIndex-1] == “$” || txt[textIndex-1] == “,”) 100 else 0

    For the dollar sign baseline shift, use a position animator (try position value of 0,10) and this expression:

    txt = text.sourceText;
    if (txt[textIndex-1] == “$”) 100 else 0

    For the taller numbers, another scale animator (scale value 100,125) and this expression:

    txt = text.sourceText;
    if (txt[textIndex-1] >= “0” && txt[textIndex-1] <= “9”) 100 else 0

    You might also want to add a fourth (tracking) animator with the same expression as the first animator to tighten things up a little.

    Dan

  • Eric Bowman

    March 24, 2011 at 2:08 pm

    Thanks so much Dan!!!

    I just learned a ton from you. I need to buy you some beer or something. This was EXACTLY what I needed. You win an AWESOME award for the day. 😉

    Eric Bowman

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