• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Can we have Number of rows & columns using the dataValue method

Participant ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

I am writing to request an enhancement to Adobe After Effects' scripting capabilities, specifically a more efficient way to ascertain the number of rows in a CSV file using the dataValue method.

 

Presently, I am able to get a count of rows using the layer("Data")("Number of Rows") method. However, this is not practical for my use case as my projects often involve up to 50 different CSV files. Integrating all these CSV files into my composition unnecessarily complicates and bloats the setup. It would be far more convenient if there was a way to directly access the number of rows using the footage("data.csv").dataValue method.

 

The necessity for this feature stems from the need to iterate through a column of data for sorting purposes. While I have developed a workaround to address this issue in the meantime, it lacks the fluidity and full automation that a built-in feature could provide. I believe that Adobe already has the backend data analysis capabilities to facilitate this feature.

 

An example of a makeshift function I use is the following:

 

javascript

Copy code

function getRowCount() {

  var i = 0;

  while (true) {

    var value = footage("data.csv").dataValue([0,i]); 

    if (value == null || value == "") {

      break;

    }

    i++;

  }

  return i;

}

However, this workaround does not function correctly when encountering blank rows in the CSV or inconsistencies in the first column.

 

Given Adobe's history of innovative and user-focused solutions, I am confident that adding this feature will greatly enhance the user experience and increase the versatility of Adobe After Effects. I look forward to seeing this functionality implemented in the future updates.

 

  • Thank you for considering my request
Idea Acknowledged
TOPICS
Expressions

Views

353

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Pinned Reply

Adobe Employee , May 18, 2023 May 18, 2023

Hi @Volition74au,

Thanks for making this feature. It certainly would be convenient to have dedicated methods for this, much like the .dataKeyCount()  method for MGJSON files.

 

Currently, there is an alternative way to look up the number of rows and columns in .csv data using the .sourceText attribute to read the data directly from the footage item and split it to find the number of elements in each dimension:

const data = footage("dataFile.csv");

// Get the number of items separated by commas 
...
Status Acknowledged

Votes

Translate

Translate
5 Comments
Adobe Employee ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Hi @Volition74au,

Thanks for making this feature. It certainly would be convenient to have dedicated methods for this, much like the .dataKeyCount()  method for MGJSON files.

 

Currently, there is an alternative way to look up the number of rows and columns in .csv data using the .sourceText attribute to read the data directly from the footage item and split it to find the number of elements in each dimension:

const data = footage("dataFile.csv");

// Get the number of items separated by commas in the first line
const numColumns = data.sourceText.split(/\n/g)[0].split(",").length;

// Get the number of newline characters that are followed by
// visible characters, minus one for the header row
const numRows = data.sourceText.split(/\n(?=\S)/g).length - 1;

[numRows, numColumns];

 

Thanks again for making this request,

- John, After Effects Engineering Team 

Status Acknowledged

Votes

Translate

Translate

Report

Report
Participant ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Thanks John for your expression. Appreciated! 

Hopefully my request is considered important enough to make a development schedule 

Votes

Translate

Translate

Report

Report
Participant ,
Aug 12, 2024 Aug 12, 2024

Copy link to clipboard

Copied

I'm having issues with the numRows part of this expression because some of my CSV files contain new line characters within the rows themselves. These are important so that my text displays correctly with the correct line breaks. I'm using a CSV to display the same text (in the cols) in different languages.

 

My CSV has 10 rows (languages) and two of the columns for each have a line break, so the expression finds reports 30 rows (10 for each actual row + 2 * 10 for the 2 columns with line breaks). 

 

Is there a way to restrict the count to just the first column of the CSV? That is where I am storing the language code and there will never be a manual line break there. 

Votes

Translate

Translate

Report

Report
Enthusiast ,
Aug 12, 2024 Aug 12, 2024

Copy link to clipboard

Copied

If your data doesn't contain any commas besides those used to separate values,
you can use this:

const data = footage("dataFile.csv");

const numColumns = data.sourceText.split(/\n/g)[0].split(",").length;
const lines = data.sourceText.split(/\n/);
const numRows = lines.filter(line => line.split(",").length === numColumns).length - 1;

[numRows, numColumns];

 

Votes

Translate

Translate

Report

Report
Participant ,
Aug 13, 2024 Aug 13, 2024

Copy link to clipboard

Copied

LATEST

Thanks for the idea, but there are other commas spread through the CSV, so this won't work for me unfortunately.

 

I've also discovered that this whole thing breaks when I make a MOGRT, bring it into Premiere, and swap out the CSV file. The reference to footage("datafile.csv") means it is always looking at the same (original) CSV file, not the swapped one. I need to reference the CSV in the comp instead (thisComp.layer("datafile.csv")) and the data.sourceText menthod doean't work .

 

Votes

Translate

Translate

Report

Report