Counting to 100.000.000

Scripting for After Effects

Counting to 100.000.000

Postby tonyworks on 06/23/2009, 2:37 am

Hello everybody,

I'm working on a scientific animation and i need a number to animate from 0 to 100.000.000
pausing at several numbers like 50, 1.000, 10.000 etc...

AE number count only goes up to 30000 and i'm trying to get a dot(.) instead of a comma(,) for the numbers over 1.000...

I found this using google http://trelhouse.com/article/41/after-e ... over-30000
but it doesn't seem to work....

who knows the solution??

Thanks a lot!
T.
tonyworks
 
Posts: 3
Joined: 06/23/2009, 2:09 am
Location: Rotterdam, The Netherlands

Re: Counting to 100.000.000

Postby tonyworks on 06/23/2009, 2:56 am

almost there!
i found this and it counts up to 1.000.000 but i can't get it to count to 1.000.000.000

----

Formatting a number with commas

1. Create a comp. Name it anything you like.
2. Create a new text layer and name it "dummy" (this layer can be turned off; it feeds a number to the final text layer. I haven't found a way around this; please let me know if there's another way).
3. Add a slider to the "dummy" layer (Effects > Expression Controls > Slider Control). After Effects should automatically name the slider control "Slider"
4. Add an expression to Source Text of "dummy" (Animation > Add Expression).
5. Pickwhip the expression to the "Slider" control from step 3.
6. Create a second text layer. This will be the layer that displays the formatted number.
7. Add an expression to Source Text of the new text layer. Replace the code with the following:

var num = thisComp.layer("dummy").text.sourceText;
num = Comma(num);
[num]

function Comma(number)
{
number = '' + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

Now try changing the value of the "Slider" control. Your visible text layer should reflect that number, now formatted with commas. Two catches: it only works for integers, and the slider tops out at 1,000,000. You should be able to pickwhip to any propery that contains a number (decimals are rounded off automatically).
tonyworks
 
Posts: 3
Joined: 06/23/2009, 2:09 am
Location: Rotterdam, The Netherlands

Re: Counting to 100.000.000

Postby Mylenium on 06/23/2009, 5:22 am

http://www.motionscript.com/design-guide/counter.html

All you need and nicely explained.

Mylenium
[Pour Mylène, ange sur terre]
----------------------------------------
www.myleniumblog.com
Mylenium
 
Posts: 3263
Joined: 02/1/2009, 11:45 am
Location: Germany
System Specs: Have, I do!

Re: Counting to 100.000.000

Postby tonyworks on 06/23/2009, 8:14 am

Thanks Mylenium!

Tony
tonyworks
 
Posts: 3
Joined: 06/23/2009, 2:09 am
Location: Rotterdam, The Netherlands

Re: Counting to 100.000.000

Postby davdalx on 05/21/2015, 10:25 am

tonyworks wrote:almost there!
i found this and it counts up to 1.000.000 but i can't get it to count to 1.000.000.000

----

Formatting a number with commas

1. Create a comp. Name it anything you like.
2. Create a new text layer and name it "dummy" (this layer can be turned off; it feeds a number to the final text layer. I haven't found a way around this; please let me know if there's another way).
3. Add a slider to the "dummy" layer (Effects > Expression Controls > Slider Control). After Effects should automatically name the slider control "Slider"
4. Add an expression to Source Text of "dummy" (Animation > Add Expression).
5. Pickwhip the expression to the "Slider" control from step 3.
6. Create a second text layer. This will be the layer that displays the formatted number.
7. Add an expression to Source Text of the new text layer. Replace the code with the following:

var num = thisComp.layer("dummy").text.sourceText;
num = Comma(num);
[num]

function Comma(number)
{
number = '' + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

Now try changing the value of the "Slider" control. Your visible text layer should reflect that number, now formatted with commas. Two catches: it only works for integers, and the slider tops out at 1,000,000. You should be able to pickwhip to any propery that contains a number (decimals are rounded off automatically).


Thanks A LOT! This was very helpful! I wish I could understand what was going on so I wouldn't have to come back here every time. Got lost at number.length % 3.
davdalx
 
Posts: 72
Joined: 11/3/2010, 6:35 am
Location: Nairobi, Kenya
Twitter: davdalx

Re: Counting to 100.000.000

Postby lrntbb2 on 06/3/2016, 3:06 am

you can also use vdodna's Counter Preset, to save all the time of coding and head bashing :
http://www.vdodna.com/products/counter-preset/
lrntbb2
 
Posts: 4
Joined: 06/3/2016, 2:58 am
System Specs: i7
32 gigs
gtx 770

Re: Counting to 100.000.000

Postby tyrone_perry on 10/24/2017, 9:00 pm

Just to modify the code above to not use a dummy layer...

1. Create text layer.
2. Add a slider control
3. paste this into source text.

var num = effect("Slider Control")("Slider")*1000 // *1000 this makes the slider be able to go beyond 1,000,000, up to 1,000,000,000
num = Comma(num);
[num] // Altering this to say something like ["$"+num] or [num+"%"] to add a dollar sign or percent to the number.

function Comma(number)
{
number = '' + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}
// Your welcome. ha ha @tyrone_perry
tyrone_perry
 
Posts: 1
Joined: 10/24/2017, 8:47 pm
System Specs: Um My computer has a gtx 1080, and uh... some seaslugs... I think.


Return to After Effects Expressions