Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Import multiple files and create a comp for each one

  • Import multiple files and create a comp for each one

    Posted by Borja Tierra on March 4, 2016 at 11:43 am

    Hi, I’m new to scripting in After Effects and I have a little problem.

    It’s possible to import multiple files at the same time and create a comp for each one?

    What i have it’s great but only for one file and I need to import different files and create a different comp for each one. Also, the number of files to be imported is always different.

    Do you have any ideas?
    This is the code I have right now:

    var myfile = app.project.importFileWithDialog(); //the file is stored in array index 1

    //Get file Attributes and set them to variables
    var myfileWidth = myfile[0].width;
    var myfileHeight = myfile[0].height;
    var myfileFrameRate = myfile[0].pixelAspect;
    var myfileFrameRate = myfile[0].duration;
    var myfileFrameRate = myfile[0].frameRate;
    var myfileName = myfile[0].name;

    //Create comp with attributes of the file
    var myComp = app.project.items.addComp( myfile[0].name, myfile[0].width, myfile[0].height, myfile[0].pixelAspect,myfile[0].duration,myfile[0].frameRate);

    Borja Tierra replied 10 years, 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • David Conklin

    March 4, 2016 at 3:52 pm

    If you’re able to collect all of the files you want to import into a folder, extend script has a ‘Folder’ object which you can use to import multiple files. We can do this by following the steps below:

    1. Have user select folder.
    2. Check that folder exists.
    3. Get the files from the folder.
    4. Make sure there were files.
    5. Loop through each file and perform some action on it (import it).

    I’ve written a little script that gets all files from a folder and prints their name. You can, of course, change the name-printing bit to the import script you have already written.

    If you’re looking for some additional control, you can use a ‘filter’ when running Folder.getFiles() to control what type of files you get (only MOVs, only PSDs, PSDs and MOVs, etc). Simply feed it an argument like “*.psd” to only get files with the .PSD extension.

    Here’s the script:
    (function importFilesFromFolder(){
    app.beginUndoGroup("Import files from folder");

    var fldr = Folder.selectDialog("Choose a folder of files to import");
    if(fldr==null) return;

    var files = fldr.getFiles("*.jsx");
    if (files.length == 0) return;

    for each (var file in files){
    $.writeln(file.fsName)
    }

    app.endUndoGroup();
    })();

    Good luck!

    David Conklin
    Motion Designer

  • Borja Tierra

    March 9, 2016 at 1:32 pm

    Thank you David!

    Esto funciona bien, no estoy usando la parte de carpeta en este momento porque prefiero importar los archivos uno por uno, pero gracias de todos modos. Comparto mi guión final si es útil a alguien.

    var myfile = app.project.importFileWithDialog();
    var myText = app.project.items.addComp( "text", 1080, 1920, myfile[0].pixelAspect,myfile[0].duration,myfile[0].frameRate);

    for (var i = 0; i < myfile.length; i++){

    var myComp = app.project.items.addComp( myfile[i].name, myfile[i].width, myfile[i].height, myfile[i].pixelAspect,myfile[i].duration,myfile[i].frameRate);
    var nameComp = myfile[i].name
    var newObj = myComp.layers.add(myfile[i]);

    var format;

    //COMP LANDSCAPE
    format = nameComp.indexOf("landscape");
    if (format != -1) {
    var addText = myComp.layers.add(myText);//adds myfile to mycomp
    myComp.layer("text").rotation.setValueAtTime(0,-90);
    myComp.layer("text").position.setValue([1180,540]);
    }

    var myRender = app.project.renderQueue.items.add(myComp);

    }

  • Borja Tierra

    March 23, 2016 at 12:31 pm

    Sorry for the spanish translation:

    This works well, I’m not using the folder part right now because I prefer to import the files one by one, but thanks anyway. I share my final script if useful to someone.

    var myfile = app.project.importFileWithDialog();
    var myText = app.project.items.addComp( "text", 1080, 1920, myfile[0].pixelAspect,myfile[0].duration,myfile[0].frameRate);

    for (var i = 0; i < myfile.length; i++){

    var myComp = app.project.items.addComp( myfile[i].name, myfile[i].width, myfile[i].height, myfile[i].pixelAspect,myfile[i].duration,myfile[i].frameRate);
    var nameComp = myfile[i].name
    var newObj = myComp.layers.add(myfile[i]);

    var format;

    //COMP LANDSCAPE
    format = nameComp.indexOf("landscape");
    if (format != -1) {
    var addText = myComp.layers.add(myText);//adds myfile to mycomp
    myComp.layer("text").rotation.setValueAtTime(0,-90);
    myComp.layer("text").position.setValue([1180,540]);
    }

    var myRender = app.project.renderQueue.items.add(myComp);

    }

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