Adding a comma to a counter via CSV imported data using Expressions
Hi,
I'm a relative novice when it comes to Expressions and Javascript so it would be great if someone could put me on the right path with my quiry.
I'm trying to add a comma to my counter in after effects.
There are 3 elements in the comp:
1) An empty text layer (the Counter)
2) A CSV file continaing 3 rows with numbers adding up to a total of 11,000
3) A Control layer with two Slider controls asigned to it:– Slider 1 named Progress, and Slider 2 named Total Value.
What I want is to have the CVS generate the counter numbers based on the tottal value of all cells (11,000 in this case). I've managed to acheive that but for some reason the figures are'nt rounding off resulting in a string of digits inbetween the start and end keyframes of the Progress slider. I would also like to add a comma seperator to the counter when the numbers go above 1,000 but currently i'm gett "11000" rather than "11,000".
Here's the code I 'm using for each of the ekements in the comp:
Counter:
totalVal = thisComp.layer("Control").effect("Total Value")("Slider");
p = thisComp.layer("Control").effect("Progress")("Slider");
linear(p, 0, 1, 0, totalVal);
Control Layer (Progress slider):
Math.round(effect("Progress")("Slider")*100)/100
Control Layer (Total Value slider):
csvname = thisComp.layer(thisComp.numLayers).name;
cellcount = thisComp.layer(csvname)("Data")("Number of Rows");
val = 0;
for (i=0; i<cellcount; i++){
val += (footage(csvname).dataValue([1,i]));
}
For the the counter 'Comma seperator' I've tried applying the below code but am a little unsure where to place it and or wether it is possible to include it as it appears to be a different type of code here:
Math.round(effect("Progress")("Slider"))
var num = effect("Progress")("Slider")
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;
}
I'd really appreciate it if someone can through some light on this for me and point out where I am going wrong.
Note: My Expressions 'Project Settings' are set to Legacy ExtendScript. For when I switch to Javascript the script does'nt work.
