Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions count from 0 to a number from a csv file

  • count from 0 to a number from a csv file

    Posted by Obed Ampong on September 19, 2018 at 5:18 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))

    Obed Ampong replied 7 years, 10 months ago 2 Members · 15 Replies
  • 15 Replies
  • Dan Ebberts

    September 19, 2018 at 5:37 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

  • Obed Ampong

    September 19, 2018 at 5:46 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.

  • Dan Ebberts

    September 19, 2018 at 5:50 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

  • Obed Ampong

    September 20, 2018 at 3:43 am

    Thanks very much. it worked.
    regards,
    Obed

  • Obed Ampong

    September 20, 2018 at 11:38 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 < 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;
    }

  • Dan Ebberts

    September 20, 2018 at 1:05 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

  • Obed Ampong

    September 21, 2018 at 3:45 am

    It worked, Thanks very much!
    Regards,
    Obed

  • Obed Ampong

    October 4, 2018 at 10:54 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 < 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;
    }

  • Dan Ebberts

    October 4, 2018 at 1:12 pm

    What does the new CSV file look like?

  • Obed Ampong

    October 4, 2018 at 3:33 pm

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

Page 1 of 2

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