Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Ae script import, search, then add to active comp

  • Ae script import, search, then add to active comp

    Posted by Liam Ethan on October 10, 2015 at 7:15 am

    So i’m trying to make a script that importing a .aep file, then add the comp file from .aep imported before to the active comp .
    I’m sorry for being so stupid but, i can’t get this to work .
    Here’s the script

    function CALL (){
    app.beginUndoGroup("Template");
    var ListTxt = List.selection.text ;
    var ScriptFile = new File($.fileName);
    var Path = ScriptFile.path + "/Folder/" + ListTxt +".aep";
    var ImportOptions = new ImportOptions(File(Path));
    var proj = app.project;
    proj.importFile(ImportOptions);
    var ICompCheck = rnPanel.grp.rnG.rnTabbedPanel.rnCMT.ImComp;
    if (ICompCheck.value){
    var Comp = app.project.activeItem;
    for(var i = 1; i <= app.project.numItems; i++) {
    if (app.project.item(i) instanceof CompItem){
    var CleanOne = i.duplicate();
    Comp.layers.add(CleanOne);
    }
    }
    }
    }
    app.endUndoGroup;

    Xavier Gomez replied 10 years, 10 months ago 2 Members · 3 Replies
  • 3 Replies
  • Xavier Gomez

    October 12, 2015 at 7:37 am

    Hi,

    one major error is the line :

    var ImportOptions = new ImportOptions(File(Path));

    (you can’t redefine ImportOptions to be something else).

    This code would do most of what you want i think, except that it doesnt duplicate the imported comps.
    Also it adds imported comps in the alphabetical order, which might be completely wrong.

    function CALL (){

    // importing a footage might change the activeItem, so get it now.
    var comp = app.project.activeItem;

    var listTxt = List.selection.text ;
    var scriptFile = new File($.fileName);
    // use this if the system folder called "Folder" is in the same directory as the script
    var path = File($.fileName).path + encodeURI("/" + "Folder" + "/"+ ListTxt +".aep");
    var file = new File(path);
    //var file = File.openDialog();
    if (file.exists){
    alert("yeah !");
    var io = new ImportOptions(file);
    if (io.canImportAs(ImportAsType.PROJECT)){
    var aeFolder = app.project.importFile(io);
    var N = aeFolder.numItems, n;
    // the variable aeFolder represents the imported project (as a folder in the project panel)
    alert("project imported !");
    if (rnPanel.grp.rnG.rnTabbedPanel.rnCMT.ImComp.value){
    //if (true){
    var j=0;
    if (comp instanceof CompItem){
    for (n=1; n<==N; n++){ if (aeFolder.item(n).typeName === "Composition"){ // add that imported comp to the active comp ++j; j===1 ? comp.layers.add(aeFolder.item(n)) : comp.layers.add(aeFolder.item(n)).moveAfter(comp.layer(j)); }; }; alert(j + " imported comps have been added to the active comp"); } else{ alert( "No comp is active. Imported comps won't be added."); }; }; } else{ alert("Can't import that file as project"); }; }; app.endUndoGroup(); return; }; CALL();

    (edit : forgot to put the code inside code tags)

  • Liam Ethan

    October 12, 2015 at 9:46 am

    Wow much complicated but i get it now, BIG THANKS Xavier !

  • Xavier Gomez

    October 12, 2015 at 5:28 pm

    I read the code again : i forgot the beginUndoGroup…
    I bet you would have realised anyway, and you’ll probably have to edit it quite a lot to get to what you actually want.

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