Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Search csv file for specific text and return specific cell

  • Search csv file for specific text and return specific cell

    Posted by Shebbe Klaasen on April 3, 2023 at 1:10 pm

    Hello all,

     

    First post here. Hope any of you can help me.
    I’m looking in to incorporating .csv files in my projects which is exciting but I’m trying to find an efficient way to find the right values of a row by looking up the asset name. That way it wouldn’t matter on which row that asset is even if it changes afterwards due to other assets being added, I’d still get the proper data injected for that particular asset. Hope that makes sense?

    For example, attached is what my sheet would look like. If my comp name would be tagon 5s the text layer for the first copy would take the source text from [2, 1].

    How would I set up the search and return?

    Thanks in advance!

    Shebbe Klaasen replied 3 years, 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • Tomas Bumbulevičius

    April 4, 2023 at 7:31 am

    Hey Shebbe, one of the way how this could be achieved:
    1. Getting length of the column.
    2. Spinning a loop through all column values to find out the matching title.

    However, it will be a slow process to render if you keep adding more and more lines to the doc.

  • Shebbe Klaasen

    April 4, 2023 at 2:21 pm

    Thanks Tomas,

    I was already looking for ways to do that. I’m not the most savvy when it comes to coding so for loops are still a bit confusing to me. I actually tried to ask AI to come up with the code and got something like this (already modified the first vars to take the bottom layer of the comp for reading the csv file):

    compName = thisComp.name;
    csvName = thisComp.layer(thisComp.numLayers).name;
    rows = footage(csvName).dataValue.split("\n");
    
    for (i = 0; i < rows.length; i++) {
    col = rows[i].split(",");
    if (col[1] == compName) {
        result = col[2];
        break;
    }
    
    }
    result;

    But what I can’t seem to understand is how the .csv files work exactly since the cells are arrays of 2 dimensions but the actual data is also a string at the same time? When using the code AE says that the 3rd line is not a function. I can’t seem to figure out how to split the data.

  • Shebbe Klaasen

    April 5, 2023 at 3:04 pm

    I’ve figured it out!

    Because the .csv file inside AE is already broken up there is absolutely no reason at all to create row/column arrays. This makes the code actually fairly straight forward. Posting it here for anyone that may run into the same challenge.

    I also added a Slider Control to the .csv layer set to 999 and parented the .csv property “Number of Rows” to it. The reason is that this data doesn’t automatically update when more rows are added when the file is changed. Now it will always loop through the available max rows.

    csvFile = thisComp.layer(thisComp.numLayers).name;
    compName = thisComp.name;
    csvLength = thisComp.layer(csvFile)("Data")("Number of Rows");
    
    for (i = 0; i < csvLength; i++) {
      stringvalue = footage(csvFile).dataValue([0, i]);
      if(compName == stringvalue){
         footage(csvFile).dataValue([2, i]);
    	 break;
      }
    	else {"Data Not Found";}
    }

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