Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Saving CSV or TXT File In AE

  • Saving CSV or TXT File In AE

    Posted by Mike LeBel on August 19, 2020 at 7:29 am

    I recently learned it is possible to create a CSV and import the data into AE for easily making a large number of changes. This has already proven to be very helpful in my project, but is it possible to do the reverse?

    I’d like to export data from AE and save it into a CSV? If it’s any easier, I would actually prefer a TXT file (which is basically the same thing). I’m guessing that will require opening a file outside of AE, write the values, and then close the document? Can expressions do this or is there another round about way?

    To help explain further, I’d like to export each ‘Layer Name’ in order for “UseThisComp”. I’m thinking I’ll also need a FOR loop, and something along the lines of what is written below?

    Am I even close here…?
    -Thanks!

    NumberOfLayers = comp("UseThisComp").numLayers //count number of layers in comp;
    //open text file for editing ("c:/change this file.txt")

    for (i = 0; i < NumberOfLayers; i++)
    thisComp.layer(x).name + "r"

    //close text file;

    Andrei Popa replied 5 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Andrei Popa

    August 19, 2020 at 8:53 am

    You can do that via scripts. Save this in a file with the .jsx extension


    var myComp = app.project.activeItem;
    var filePath = app.project.file.path + "/" + myComp.name + ".txt";
    var layerList = createTextFromComp(myComp);
    createFile(filePath, layerList);

    function createFile(filePath, content) {
    var myFile = new File(filePath);
    if (myFile.open("w")) {
    myFile.encoding = "BINARY";
    myFile.write(content);
    myFile.close();
    } else {
    alert("Error opening file " + myFile.displayName + ": " + myFile.error, "Function createFile");
    }
    }

    function createTextFromComp(myComp) {
    layerNames = [];
    numberOfLayers = myComp.numLayers;
    for (var i = 1; i <= numberOfLayers; i++) {
    layerNames.push(myComp.layer(i).name);
    }
    return layerNames.join("\n");
    }

    Then, before running this, make sure that your project is saved.
    Run the script by File>Scripts>Run Script File… and choose the file you saved.
    It will create a txt file in the same destination as your project with the comp name and inside the list of all the layers.

    Andrei
    My Envato portfolio.

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