ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

count from 0 to a number from a csv file

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Obed Ampong
count from 0 to a number from a csv file
on Sep 19, 2018 at 5:18:58 pm

Hi,
I am trying to count from 0 to a number from a csv file.
I tried this expression below but it does not count. Please is there any way out?
Thanks in advance
Regards
Obed

startCount = 0;

endCount = idx = parseInt(thisComp.name.match(/\d+/),10)-1;
footage("cities.csv").dataValue([idx,2]);

countDur = 4;

Math.round(linear(time,0,countDur,startCount,endCount))


Return to posts index

Dan Ebberts
Re: count from 0 to a number from a csv file
on Sep 19, 2018 at 5:37:31 pm

It's not clear what your comp name looks like, or what's in your data file, but it doesn't look like you're doing anything with the CSV data. Maybe your endCount should be set to the value from the CSV file?

Dan



Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Sep 19, 2018 at 5:46:44 pm

Thanks, Dan for the reply, I am trying to set the value to the data on the csv data. At the same time, I want the value to change automatically when I duplicate the entire comp.


Return to posts index


Dan Ebberts
Re: count from 0 to a number from a csv file
on Sep 19, 2018 at 5:50:17 pm

>I am trying to set the value to the data on the csv data.

The way you have it set up, this line:

footage("cities.csv").dataValue([idx,2]);

doesn't do anything. I don't have any way to test it, but I'm guessing maybe this is what you want:



startCount = 0;

idx = parseInt(thisComp.name.match(/\d+/),10)-1;
endCount = footage("cities.csv").dataValue([idx,2]);

countDur = 4;

Math.round(linear(time,0,countDur,startCount,endCount))



Dan



Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Sep 20, 2018 at 3:43:09 am

Thanks very much. it worked.
regards,
Obed


Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Sep 20, 2018 at 11:38:11 am

Hello Dan,
Please, I have one issue. I would like the expression to refer to the layer time instead of the comp time so that I can offset the layer to any time and the expression will begin at that time. Could you kindly help me out?
Thanks in advance.

Regards,
Obed

startCount = 0;

idx = parseInt(thisComp.name.match(/\d+/),10)-1;
endCount = footage("cities.csv").dataValue([idx,2]);

countDur = 2;

var num = Math.round(linear(time,0,countDur,startCount,endCount))
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 &lt; 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;
}


Return to posts index


Dan Ebberts
Re: count from 0 to a number from a csv file
on Sep 20, 2018 at 1:05:25 pm

Try changing this line:

var num = Math.round(linear(time,0,countDur,startCount,endCount))

to this:

t = time - inPoint;
var num = Math.round(linear(t,0,countDur,startCount,endCount));


Dan



Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Sep 21, 2018 at 3:45:41 am

It worked, Thanks very much!
Regards,
Obed


Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Oct 4, 2018 at 10:54:28 am

Hi Dan,
Please, I changed the CSV file and After Effects says there is an error in line 4. Could you kindly help me out?
Thanks always.

Regards,
Obed

startCount = 0;

idx = parseInt(thisComp.name.match(/\d+/),10)-1;
endCount = footage("COMPANIES.csv").dataValue([idx,4);

countDur = 3;

t = time - inPoint;
var num = Math.round(linear(t,0,countDur,startCount,endCount));


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 &lt; 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;
}


Return to posts index


Dan Ebberts
Re: count from 0 to a number from a csv file
on Oct 4, 2018 at 1:12:44 pm

What does the new CSV file look like?



Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Oct 4, 2018 at 3:33:41 pm

It has 7 rows and 50 columns. I made it with excel just like the first one


Return to posts index

Dan Ebberts
Re: count from 0 to a number from a csv file
on Oct 4, 2018 at 4:02:43 pm

It looks like you left out a close bracket ] at the end of line 4.

Dan



Return to posts index


Obed Ampong
Re: count from 0 to a number from a csv file
on Oct 4, 2018 at 4:04:57 pm

Hi Dan,
I have rectified the error. Thanks a lot.

Regards, Obed


Return to posts index

Obed Ampong
Re: count from 0 to a number from a csv file
on Oct 12, 2018 at 5:19:16 pm

Hi Dan,
Please, is it possible to add the Dollar symbol $ to the expression so that the symbol will be in front of the numbers?
Thanks

Regards,
Obed


Return to posts index

Dan Ebberts
Re: count from 0 to a number from a csv file
on Oct 12, 2018 at 5:28:11 pm

Try changing this line:

[num]

to this

"$" + num


Dan



Return to posts index


Obed Ampong
Re: count from 0 to a number from a csv file
on Oct 12, 2018 at 6:42:29 pm

WOW!!!
Thanks so much Dan. You've been very helpful.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]