Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making numbers have proportional spacing controlled by an expression.

  • Making numbers have proportional spacing controlled by an expression.

    Posted by Kev Craven on September 25, 2012 at 2:30 pm

    Hi all,

    I have a project where there’s an expression and sliders controlling the value of a number. I had to use an expression because I couldn’t go higher than 30,000 using ‘numbers’ but one feature from ‘numbers’ that I need is to uncheck the proportional spacing option, so the spacing of the text isn’t jumping around all over the place.

    Does anyone know of a workaround?

    here's my source text expression (found online)

    s = effect("value")("Slider");
    m = effect("multiplier")("Slider"); //use for numbers greater than 1 million
    v = s*m; //value of counter

    function digits(Val, Digits)
    {var n = Val.toString(); while (n.length < Digits) n = '0' + n; return n;}

    h = Math.floor(v);
    t = Math.floor(h / 1000);
    m = Math.floor(t / 1000);
    b = Math.floor(m / 1000);

    hd = digits(h-t * 1000, 3);
    td = digits(t-m * 1000, 3);
    md = digits(m-b * 1000, 3);

    if (v < 1000) {h} else if (v < 1000000) {t + "," + hd} else if (v < 1000000000) {m + "," + td + "," + hd} else {b + "," + md + "," + td + "," + hd}

    Will Eccleston replied 11 years, 4 months ago 5 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    September 25, 2012 at 3:28 pm

    Can you use a monospaced font?

    Dan

  • Robert Shaw

    July 8, 2013 at 1:01 pm

    I’m posed with this very issue myself at the moment. Just to reiterate I have a number counter going up to 400,000 and due to the comma I haven’t been able to use a slider.

    The issue is that I also need it to have proportional spacing to prevent the number from jumping all over. The solution of using a monospaced font in the previous comment is a no go unfortunately as I am having to work with a specific font set.

    Any ideas as to how I could incorporate proportional spacing into my expression?

  • Nate Vander plas

    December 5, 2014 at 5:04 pm

    I really need a solution for this as well. Using a mono spaced font is almost never an option for me, and definitely not in this case. I love the ease of use of Dan Ebbert’s expression for counting on his site except for this one issue. I tried writing my own, using each decimal as a separate layer and manually placing them in the correct position with commas. I thought I could link the source text to an angle control with a different multiplier for each decimal that would let me cycle 0 through 9 and repeat, but that doesn’t work. Any ideas? In my current project I don’t need the number of decimals to change (it’s a range from about 100,000,000 to 165,000,000).

  • Nate Vander plas

    December 5, 2014 at 8:20 pm

    UPDATE:
    I figured out a solution. I hunted around this forum for other expression options and here’s what I did. I created a separate text layer for each digit in my number and placed it manually in the proper position with my commas. Then I also created a text layer “Master Number” with an expression linking it to an animated slider:
    Math.floor(effect(“Slider”)(“Slider”))
    Then for each digit I applied this expression to the source text linking it to one number from the Master Number:
    thisComp.layer(“Master Number”).text.sourceText[0]
    The [0] here represents the first digit in my Master Number, so I changed this to 1, 2, etc. for each subsequent digit layer. I found out that sliders can only go up to 1,000,000, but I needed 2 more digits. I could have made another Master Number with a different slider animation, but those last three digits would be moving so fast that no one would be able to tell if they were counting up or down. I applied a random number expression for each of these:
    rate = 24; //how many times per second it changes the number
    seed = Math.floor(time*rate);
    seedRandom(seed,true);
    “” + Math.floor(random(10));

    Math.floor(effect("Slider")("Slider"))

    thisComp.layer("Master Number").text.sourceText[0]

    rate = 24;
    seed = Math.floor(time*rate);
    seedRandom(seed,true);
    "" + Math.floor(random(10));

  • Will Eccleston

    December 18, 2014 at 3:47 pm

    Or the super-easy way (if you are on a Mac) – use Motion to create your counter. Essentially automatic, with nice kerning in any font. Within Motion, go to: Library/Generators/Text Generators/Numbers, and apply the Numbers Generator to your comp. Set the start and end value and the font, making it bigger than you need. Render with Alpha. Done. Bring it into AE and place it. For several years I used Motion extensively, but had to give it up, begrudgingly, for AE, since no one else knew how to step into my Motion projects for revisions. There are a ton of things that it does better, faster, cleaner, and easier than AE. A number counter that doesn’t involve programming and rigging seems like such a fundamental thing that AE would have. But there are tons of those things…

    Will Eccleston
    Kinetiscape Films
    https://vimeo.com/album/132368

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