After Effects Tutorial - Expressions for Animated Number Counter with Slider Control

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 พ.ค. 2020
  • Thanks for viewing! / andyfordvideo
    Videos with number animations look slick. Why just display a static number or percentage on screen when you can have an animation scrolling the numbers up to your target number?
    You can create many numeric animations efficiently with just one layer in your composition by applying the Slider Control effect and using an expression. I get a lot of questions about how to do this, as figuring out the proper expression can be confusing when it comes to rounding numbers or adding commas to large numbers.
    Well, wonder no more! My video tutorial will show you a couple key expressions you need to know when dealing with this situation. Advanced knowledge of expressions is not needed, just how to copy and paste. You’ll learn how to apply the Slider Control and create the expression. Then, you’ll learn how to amend the expression based on if you are trying to round the number to a whole number, have a select number of digits after the decimal point, and/or add a comma in the number.
    I’ve provided the expressions below for your copy/paste needs, so just watch the video to see where and how to place them.
    Note that creating an expression is done by doing an Alt-click (Windows) or Option-click (Mac) on the stopwatch icon in the layer's property. Whenever you link the source text property of your layer to the slider control value, you’ll see this text appear in the expression area:
    effect("Slider Control")("Slider");
    However, when your numbers scroll between set keyframes, you’ll have a lot of digits after the decimal. To alleviate this, you need to tell After Effects to round the number. In my opinion, the quickest way to do this is to amend the expression to the following:
    Math.round(effect(“Slider Control”)(“Slider));
    Note that capitalization matters. It has to be Math, not math. Now, you will have whole numbers with no decimal point.
    If you want to add a comma to your number value so you get 1,000 instead of 1000, the expression is quite complex. This is where copy and paste come into play. Erase what you have in the expression area and paste this:
    num = effect("Slider Control")("Slider").value.toFixed();
    function addCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
    addCommas(num);
    Breaking this down, the top line provides what the variable equals. “Slider Control” is whatever you name the Slider Control effect. By default, it is Slider Control, but some people rename their effects.
    Adding .value.toFixed() is important (note the capital “F”). Without this addition, your number will have a significant amount of digits after the decimal point. Inside the parenthesis, you can add a numeric value. This value will be how many digits you want to see after the decimal point. To add two digits after the decimal point, the expression is as follows:
    num = effect("Slider Control")("Slider").value.toFixed(2);
    function addCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
    addCommas(num);
    The rest of the expression tells After Effects where to add a comma. toString() is a Java method that returns the value given to it in string format. What follows is a regular expression pattern that searches the string and adds a marker after 3 consecutive digits. Then, it replaces that marker with a comma.
    #adobe #aftereffects #motiongraphics #video #tutorial #vfx #expressions

ความคิดเห็น • 247

  • @christopherposthuma5948
    @christopherposthuma5948 3 ปีที่แล้ว +16

    How would you add say a dollar sign ($)
    to the beginning of the number?

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +31

      You would still make your text layer and add the slider control to it. Under the Source Text twirl-down, use this expression from the great Dan Ebberts. This will add a dollar sign, comma as needed, and befittingly round to two spaces after the decimal point.
      numDecimals = 2;
      commas = true;
      dollarSign = true;
      dur = 4;
      s = effect("Slider Control")("Slider").value.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;
      }

    • @christopherposthuma5948
      @christopherposthuma5948 3 ปีที่แล้ว

      Thanks!

    • @emeraldleong
      @emeraldleong 3 ปีที่แล้ว

      @@AndyFordVideo please pin this comment to the top vv helpful info. thanks again for this video!!

    • @itslitepower
      @itslitepower 3 ปีที่แล้ว +1

      @@AndyFordVideo How do you add a text after the number? The code looks like this, for example, "$100,000". I want to make it "$100,000?"

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      @Ken Garcia a manual way that gives you the most control with kerning and alignment would be to just add the ? as a text layer. If you are center justified and the positioning changes as the number grows in digits, you can keyframe your ? to move to the right as the number of digits grows.

  • @thegerardo981
    @thegerardo981 3 ปีที่แล้ว +5

    LIFESAVER!! Thank you so much good sir!! Been struggling with this for HOURS!! This channel deserves waaay more recognition.

  • @MouseOnFeet
    @MouseOnFeet ปีที่แล้ว +2

    Thank you so much! I've watched 7 tutorials prior to this that would either leave me with decimals or no commas and this finally got me over the hump. Super appreciate you

  • @brettricheatwork
    @brettricheatwork 3 ปีที่แล้ว +10

    This is so much simpler than some of the other tutorials, I wish that this was getting more traction on TH-cam than it is.

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว

      Thank you! It's my goal to provide quick tutorials that get to the point.

  • @Xandertank2010
    @Xandertank2010 ปีที่แล้ว +1

    great tutorial! I have struggled with the commas for quite some time and all the solutions where a little crazy. thank you!

  • @PaulMcgeoch
    @PaulMcgeoch ปีที่แล้ว +1

    Thank you! This is very clever and helpful. I've always struggled with commas and decimal points till now : )

  • @MegaZayniddin
    @MegaZayniddin 2 ปีที่แล้ว +1

    Thank You. It helped me very much, was looking this tutorial for a long time

  • @slavaukraini8886
    @slavaukraini8886 2 ปีที่แล้ว +1

    Thank you very much for your very helpful and at the same time short lessons!

  • @sethfowler6680
    @sethfowler6680 ปีที่แล้ว +1

    THANK YOU! All i needed to do for my project was add a comma and you saved me LOADS of time

  • @utahwaxwing
    @utahwaxwing 2 ปีที่แล้ว +1

    Thank you Andy for sharing this.

  • @cryogenik5269
    @cryogenik5269 3 ปีที่แล้ว

    Thanks for this video, Andy! Was struggling to add that comma, and this was so simple and elegant. Cheers!

  • @mrkleinhond
    @mrkleinhond 2 ปีที่แล้ว +1

    Thank you for getting to the points I needed.

  • @user-kr5eb3dk9m
    @user-kr5eb3dk9m 2 ปีที่แล้ว +1

    Life saving tutorial this is. Thanks!

  • @icarodrasan
    @icarodrasan 2 ปีที่แล้ว +3

    Andy, you deserve a Nobel After Effects Prize. Thanks!

    • @AndyFordVideo
      @AndyFordVideo  2 ปีที่แล้ว +1

      Ha, thanks! The hard work was done by the coders. I just help you get what you need quickly.

  • @atraiobaker7871
    @atraiobaker7871 3 ปีที่แล้ว +1

    thanks for your quick and to the point tutorial! I really appreciate it !

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      Thank you for that feedback! Glad you enjoyed it!

  • @54CFL
    @54CFL 2 ปีที่แล้ว +1

    Amazing! Thanks Andy

  • @sophielondon8322
    @sophielondon8322 3 ปีที่แล้ว +1

    THANK YOU!!! So helpful.

  • @imovertheocean
    @imovertheocean 3 ปีที่แล้ว

    THANK YOU SO MUCH! Worked for me on mac. For dummies like me, make sure you are pasting the expression code in the source text field

  • @effernando
    @effernando ปีที่แล้ว +1

    Thank you sir! Hope you are having a great day!

  • @bgstudioz
    @bgstudioz 2 ปีที่แล้ว +1

    This is so helpful,. Thank you so much

  • @KookyCraftables
    @KookyCraftables ปีที่แล้ว +1

    thanks so much... this was a huge help to me.

  • @leeheffron623
    @leeheffron623 3 ปีที่แล้ว +1

    Worked perfectly...really simple solution. Cheers Andy!

  • @me.in.berlin
    @me.in.berlin 4 หลายเดือนก่อน +1

    Perfect! Simple and saved me! Thanks

  • @yanraychuk
    @yanraychuk 2 ปีที่แล้ว +1

    Thank you! Very useful.

  • @mikael2464
    @mikael2464 2 ปีที่แล้ว +1

    Perfect! Thank you!

  • @lexdelicten3094
    @lexdelicten3094 3 ปีที่แล้ว +1

    Greatest! Thank you so much

  • @lucapon
    @lucapon 3 ปีที่แล้ว +1

    thank youuuuuu. I wanted to put a dot, not a comma, and i just changed the expression in "," for "." and it works FINALLY. Thank you so so so much.

    • @choichi8938
      @choichi8938 2 ปีที่แล้ว

      how did you that?

    • @choichi8938
      @choichi8938 2 ปีที่แล้ว

      ah, i've found it, thank you

  • @bensteele8918
    @bensteele8918 2 ปีที่แล้ว +1

    Very helpful. Thanks!

  • @santiag0pictures
    @santiag0pictures 3 ปีที่แล้ว +1

    Thank you so much for your help

  • @artandgrow9240
    @artandgrow9240 3 ปีที่แล้ว

    This worked like a charm! YOU ARE AMAZING ♥

  • @shibuvera9234
    @shibuvera9234 3 ปีที่แล้ว +1

    Thank you so much!

  • @weekendmanager
    @weekendmanager 3 ปีที่แล้ว +1

    This so simple and it WORKS. Thanks you so much.

  • @mglagl
    @mglagl ปีที่แล้ว +1

    You saved my day, Thank you.

  • @scherbatson
    @scherbatson 3 ปีที่แล้ว +2

    YOU'RE A LIFE SAVER! thank you so much!!

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว

      Thanks so much, appreciate the feedback!

  • @xDaShaanx
    @xDaShaanx 2 ปีที่แล้ว +1

    Brilliant. Thanks a lot for this. :)

  • @AmrAlchalati
    @AmrAlchalati 2 ปีที่แล้ว

    Thanks for the information!

  • @SkillsNT
    @SkillsNT 3 ปีที่แล้ว

    Thank you! Really useful!

  • @archfiendwg
    @archfiendwg 2 ปีที่แล้ว

    Thanks bro. This is very useful 😍😍

  • @maxi.visuals
    @maxi.visuals 3 ปีที่แล้ว +1

    Thank you!

  • @KentHeckel
    @KentHeckel 3 ปีที่แล้ว +1

    wowowow so helpful. Thank you for the no BS tut

  • @josephkabalila9807
    @josephkabalila9807 ปีที่แล้ว +1

    really helpful thank you

  • @evansojuka1399
    @evansojuka1399 2 ปีที่แล้ว +1

    Thank you so much Sir God bless you

  • @maStein_xz
    @maStein_xz 2 ปีที่แล้ว +1

    You are the best!!! Thanks)

  • @yewsoonfatt
    @yewsoonfatt ปีที่แล้ว

    Thank you! Your tutorial is the best. you saved my day!

  • @MonsterCondition
    @MonsterCondition 3 ปีที่แล้ว +1

    Thank you so much! It was really helpfull!

  • @raghunaut
    @raghunaut 2 ปีที่แล้ว

    Thank you Andy Ford. I have learnt a technique. Found your video useful.

  • @danagustin9931
    @danagustin9931 3 ปีที่แล้ว

    Very helpful! Thank you so much!

  • @TheTerryMendez
    @TheTerryMendez 10 หลายเดือนก่อน +1

    Thank you, this really helped me out. :)

  • @user-dj4yu4cc6l
    @user-dj4yu4cc6l 2 ปีที่แล้ว

    AWESOME thanks so much!

  • @hansenchan7583
    @hansenchan7583 2 ปีที่แล้ว +1

    Thank you very much

  • @citydoor4239
    @citydoor4239 3 ปีที่แล้ว +1

    very professional explaining, all in one

  • @ensn860
    @ensn860 3 ปีที่แล้ว +1

    thank you!

  • @izzydoesart3297
    @izzydoesart3297 2 ปีที่แล้ว +1

    Sirrr...
    Thank you so much

  • @craigpattenden
    @craigpattenden 3 ปีที่แล้ว +1

    You're the real MVP

  • @jazmintabuena
    @jazmintabuena 3 ปีที่แล้ว +1

    You're a life saver! Thank you :)

  • @rasheedalrashedi
    @rasheedalrashedi 2 ปีที่แล้ว +1

    Thanks man

  • @medhachimofficial
    @medhachimofficial 9 หลายเดือนก่อน +1

    Thank You

  • @ebbyvideography
    @ebbyvideography 3 ปีที่แล้ว

    Thank you so much

  • @PROGAMING-ec7kn
    @PROGAMING-ec7kn 3 ปีที่แล้ว +1

    thankyou soo much

  • @sefabesleyici1862
    @sefabesleyici1862 2 ปีที่แล้ว +1

    Thank you so much...

  • @MrMTM4u
    @MrMTM4u 2 ปีที่แล้ว +1

    Very helpful

  • @mukeshtp4951
    @mukeshtp4951 2 ปีที่แล้ว +1

    Wonderful !!!

  • @caleb.justice
    @caleb.justice 5 หลายเดือนก่อน

    Is there a way to add an effect when the numbers change? Like a slide-down/fade-out? Or just a fade in and out? Thanks!

  • @markraimondeau3372
    @markraimondeau3372 3 ปีที่แล้ว +1

    Thankyou!

  • @jitsanimator3514
    @jitsanimator3514 3 ปีที่แล้ว +2

    thanks bro

  • @justinebautista386
    @justinebautista386 3 ปีที่แล้ว

    Thanks! That was helpful!

  • @AndresFernandez-fi4ie
    @AndresFernandez-fi4ie 2 ปีที่แล้ว +1

    Thanks!

  • @ErikFontes
    @ErikFontes 2 ปีที่แล้ว

    THANK YOU!

  • @antond.7332
    @antond.7332 2 ปีที่แล้ว +1

    thnks bro!

  • @Zeynep-lr3nk
    @Zeynep-lr3nk 3 ปีที่แล้ว

    Finally a code that works!! thank you so much

  • @ziqiang3717
    @ziqiang3717 2 ปีที่แล้ว +1

    Thank you

  • @A_Pickstone
    @A_Pickstone 3 ปีที่แล้ว +1

    Thank you :)

  • @RonaldvallejoA
    @RonaldvallejoA ปีที่แล้ว

    Fantastic video mate

  • @bizvido1583
    @bizvido1583 ปีที่แล้ว +1

    thank you

  • @nea174
    @nea174 3 ปีที่แล้ว

    Hi! your videos are helpful and to the point! How could you make a countdown timer? Trying to find a way to create a timer that counts down x number of seconds. I have seen people use the time expression but this contains hour minutes & ms which is too much, only seconds is needed.

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว

      You make a countdown timer with a slider control and a long expression or without expressions using the Numbers effect. I think I'll make my next tutorial this month on this, possibly showing both options. Thanks for the suggestion!

  • @charlesagnew3801
    @charlesagnew3801 2 ปีที่แล้ว

    How would you be able to do € symbol but it sits after the numerical value and has a space - for e.g. 1000,0 €

  • @G_g_Boys
    @G_g_Boys 10 หลายเดือนก่อน +1

    Thank youuuuuuuu❤❤💕💕💕💕

  • @selimozubek8506
    @selimozubek8506 3 ปีที่แล้ว +1

    Thanks

  • @PookBeats
    @PookBeats 2 ปีที่แล้ว

    Hey Andy, thanks for this video! Is there a way to add an ease in/out so that the count starts a bit slower, speeds up, then slows a bit as it reaches the final slider position?

    • @AndyFordVideo
      @AndyFordVideo  2 ปีที่แล้ว

      Glad you liked it. If you are using a keyframed slider control, then you can do any normal keyframe operations to these keyframes, such as ease in/out.

  • @Albania123_aaa
    @Albania123_aaa ปีที่แล้ว

    Thanks a lot 🙏🏻🙏🏻

  • @mostafacreative
    @mostafacreative ปีที่แล้ว +1

    soft is rather complex.. sotNice tutorialngs more than they should be. But you've made a great job explaining it!

  • @muneebparammal7710
    @muneebparammal7710 2 ปีที่แล้ว

    Is there any way to add + after the number eg:- 100+

  • @nadialee94
    @nadialee94 3 ปีที่แล้ว

    Hello, Andy. This was amazingly helpful. However, I was curious how to slow down the numeric animation? It goes by really fast and I want to slow it down to design my UI dashboard. Thank you so much!

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      Just space out your slider keyframes further

  • @paulinakazmierczak5090
    @paulinakazmierczak5090 2 ปีที่แล้ว

    Thank you a loot!!

  • @gabrielbiehl7
    @gabrielbiehl7 2 ปีที่แล้ว +1

    MUITO OBRIGADO!

  • @robs8552
    @robs8552 3 ปีที่แล้ว +1

    Hi Andy, great tutorial! Do you know how I would be able to start with 0000 instead of just 0?

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      Thanks. Take the beginning of the expression we used:
      num = effect("Slider Control")("Slider");
      and then on the next two lines put this to add padding to your string:
      x = 4 - num.toString().length;
      "000".substr(0,x) + num

  • @pitrubio
    @pitrubio 2 ปีที่แล้ว +1

    GRACIAS, GENIO!!!

  • @jlmotionvfx
    @jlmotionvfx ปีที่แล้ว +1

    thanksss

  • @PyrusDamian
    @PyrusDamian 2 ปีที่แล้ว +1

    thanks
    :)

  • @philipdonegan4261
    @philipdonegan4261 3 ปีที่แล้ว +1

    Thank you, I searched everywhere online for this

  • @Mintyygal
    @Mintyygal 3 ปีที่แล้ว

    Is there any way we could add commas in an INR value? the comma position in $ value and INR are different...

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว

      Yes, but not with this expression. This places a comma every certain number of digits. Yours would be more complex because you would need an expressions that leaves 3 spaces before a comma first and then 2 spaces after that. Check out this thread: creativecow.net/forums/thread/need-help-in-moving-the-comma/

  • @lowdandcleer
    @lowdandcleer 3 ปีที่แล้ว +2

    Do you know how I would replace the decimal with a comma (in other words, numbers shown in FR and SP use commas instead of decimals and vice versa)? For example, 25.2 becomes 25,2. Great video!

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      You could try making a variable and then using the toString/replace function: x.toString().replace(".", ",")

    • @lowdandcleer
      @lowdandcleer 3 ปีที่แล้ว +3

      @@AndyFordVideo Genius, thanks so much! I wrote this below and it worked, for anyone interested. The function frNumbers just means "French numbers". The only thing I am wondering for future needs: in French 6,000.00 would be written as 6 000,00. In other words, the comma is replaced by a space. I tried your formula replacing "," with " " but it seems to delete anything after a comma if I do that. I am thinking it's just a matter of turning the space needed into a string somehow? Thanks again!
      num = effect("Slider Control")("Slider").value.toFixed(3);
      function addCommas(x) {

      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

      }
      function frNumbers(x){
      return x.toString().replace(".", ",")
      }
      addCommas(num);
      frNumbers(num);

    • @Vijoodruid
      @Vijoodruid 2 ปีที่แล้ว

      @@AndyFordVideo can anyone explain, or show the code for this? I have 10,000 and the numbers are working fine, just not able to add the comma after 10

  • @Warwicka
    @Warwicka 2 ปีที่แล้ว

    Alex, this is great but could I ask how you code say an 'M' at the end (for million)? That would be useful too. Thanks

  • @Wvk5zc
    @Wvk5zc 2 ปีที่แล้ว

    How do you apply "dampened/delay" effect so that the numbers dont change too fast (eg. refresh every X miliseconds)

    • @AndyFordVideo
      @AndyFordVideo  2 ปีที่แล้ว

      timing is controlled by the spacing of your beginning and end keyframes. The more time you give the animation to happen, the slower it goes to the number you've chosen. You could also use math to alter the expression values. For example, you could divide by 2 to slow things down, multiply by 2 to speed things up by essentially skipping some numbers.

  • @zamalekeffect3272
    @zamalekeffect3272 2 ปีที่แล้ว

    Thank yoooou

  • @ChillzKent
    @ChillzKent 8 หลายเดือนก่อน +1

    thx mate real g

  • @jilc-cr5616
    @jilc-cr5616 2 ปีที่แล้ว

    how can do it expotentially? meaning transition is slow first then it would fast as it reach the last number? thanks for the answer

    • @AndyFordVideo
      @AndyFordVideo  2 ปีที่แล้ว

      through keyframing, or you could even explore tying the speed to a variable such as time*time for a speed ramp up.

  • @WeAllBurnStuff
    @WeAllBurnStuff 3 ปีที่แล้ว

    This code is working great but there's one thing I can't seem to get to work. I'm trying to go from '0.0' to '2.1' and then the numbers tick up, whenever it gets to a whole number, the decimal point disappears. So instead of it going '2.0', '2.1' it goes '2', '2.1'. Any idea how to fix this to always show the decimal place?

    • @AndyFordVideo
      @AndyFordVideo  3 ปีที่แล้ว +1

      the value.toFixed() with the number in the parenthesis of your choosing is what you want. Go to the video at 3:35 and see how the numbers after the decimals stay even when its on a whole number.

  • @chrislockwood2373
    @chrislockwood2373 2 ปีที่แล้ว

    Is there a way to use increments? For example, I want to animate the readout on a piece of drilling equipment that measures the weight of something in tens of thousands of pounds. The equipment is designed so that it rounds up or down by 500 pounds making it easier for the operator to use.

    • @AndyFordVideo
      @AndyFordVideo  2 ปีที่แล้ว +1

      Your expression for your source text would be:
      num=effect("Slider Control")("Slider");
      Math.round(num/500)*500;
      Then, everytime your slider control got to 500, 500 would appear. At 1000, 1000 would appear.

    • @chrislockwood2373
      @chrislockwood2373 2 ปีที่แล้ว

      @@AndyFordVideo thanks. This is very helpful. I did find a work around in the meantime. Is simply made a precomp where the range was 0 to 250,000 with exactly 501 frames. This made the increment for each frame 500. I then added the precomp to my comp and used time remap to keyframe the range I needed.
      Appreciate your quick response!

  • @lorenzopantani2236
    @lorenzopantani2236 ปีที่แล้ว

    Great tutorial Andy! I've got a problem though: I need to have 2,000,000 as the highest value, but the slider doesn't go more than 1,000,000. How can I sort this out? Could you please help? Thanks in advance!

    • @AndyFordVideo
      @AndyFordVideo  ปีที่แล้ว

      you can increase the max slider value through multiplication in the expression, or use point control