Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions how to add a file to a composition ?

  • how to add a file to a composition ?

    Posted by Reko Tomo on April 26, 2016 at 5:54 am

    This is my first time creating a script for After Effect.

    var photosFolder = app.project.importFileWithDialog();

    var proj = app.project;
    var PhotoComp1 = proj.items.addComp("Photo Comp1", 320, 180, 1, 08, 30);
    var PhotoComp2 = proj.items.addComp("Photo Comp2", 320, 180, 1, 08, 30);
    var PhotoComp3 = proj.items.addComp("Photo Comp3", 320, 180, 1, 08, 30);

    var newObj = PhotoComp1.layers.add.photosFolder(01.jpg); // my stupid guessing and of course it doesn't work

    //importing a folder with a name “Photos”. Inside this “Photos” Folder there are six different pictures with the name 01.jpg until 06.jpg … but these are not a sequenced scenes.

    //I want to add 01.jpg and 02.jpg from the “Photos” project bin (after imported to the project) into the Photo Comp1. These two layers need to be in 3D in the timeline, while the 02.jpg Z position is 1.

    I’ve been thinking to make a loop three times, so it happen the same for Photo Comp2 with 03.jpg and 04.jpg and for Photo Comp3 with 05.jpg and 06.jpg, but I don’t know how to write the language to do that at all.

    After that I will make a New Comp
    var MainComp = proj.items.addComp("Main Comp", 1280, 720, 1, 08, 30);

    Then I want to put the Photo Comp1 into the Main Comp with a keyframe X rotation value = 0 degree at the third second and 180 degree at the fourth second.

    Apply Trapcode Echospace to the Photo Comp1 layer. From this part, I’ve been thinking in two way :

    A. Save an Animation Presets after I tweak the Echospace control, then call the animation preset via the script.

    or

    B. Tweak the Echospace control within the script.
    This way I think it’s more difficult as I also need to know further what is the script language for putting the value in any of the Echospace control.

    But to be honest, I’m interested in both ways.

    Any kind of help would be greatly appreciated.
    Thank you in advanced.
    (I’m sorry for my broken English)

    regards.

    Reko Tomo replied 10 years ago 2 Members · 5 Replies
  • 5 Replies
  • Reko Tomo

    April 26, 2016 at 2:35 pm

    Below is so far I get from the internet.

    var PhotoComp1 = proj.items.addComp("Photo Comp1", 320, 180, 1, 08, 30);
    var PhotoComp2 = proj.items.addComp("Photo Comp2", 320, 180, 1, 08, 30);
    var PhotoComp3 = proj.items.addComp("Photo Comp3", 320, 180, 1, 08, 30);
    var picName1 = "01.jpg"; // name of item you're looking for
    var myPic1 = null;
    for (var i = 1 ; i <= app.project.numItems; i++){

    if (app.project.item(i).name == picName1){

    myPic1 = app.project.item(i);

    break;

    }

    }

    if (myPic1 != null){
    var myLayer1 = PhotoComp1.layers.add(myPic1).threeDLayer=true;

    }else{

    alert ("Can't find comp '" + picName1 + "'");

    }

    Until that, it works. But then I don’t know how to coding the position of myPic1 layer in the PhotoComp1 composition before else command.

    I’ve tried this

    myLayer1.property("ADBE Transform Group").property("ADBE Position").setValue([160,90,1]); Not work.

    I’ve tried this :

    myLayer1.myPic1.property("ADBE Transform Group").property("ADBE Position").setValue([160,90,1]); No luck.

    I’ve also tried this :

    myLayer1.layer(myPic1).property("ADBE Transform Group").property("ADBE Position").setValue([160,90,1]); No joy.

    Also I try this :

    var myPhotoComp1 = app.project.myLayer1;

    myPhotoComp1.myPic1.property("ADBE Transform Group").property("ADBE Position").setValue([160,90,1]);

    and this

    var myPhotoComp1 = app.project.myLayer1;
    myPhotoComp1.layer(myPic1).property("ADBE Transform Group").property("ADBE Position").setValue([160,90,1]);
    Both not work.

    I’d be glad if someone can help me.
    BTW, I’m using Adobe After Effect CS3.

    Thank you.

  • Dan Ebberts

    April 26, 2016 at 4:34 pm

    I haven’t tested anything, but I’m guessing your problem may be with this line:

    var myLayer1 = PhotoComp1.layers.add(myPic1).threeDLayer=true;

    I’d try it this way:

    var myLayer1 = PhotoComp1.layers.add(myPic1);
    myLayer1.threeDLayer=true;

    then see if your .setValue works.

    Dan

  • Reko Tomo

    April 26, 2016 at 7:50 pm

    Wow…. thank you very much, Dan.
    It works !

    So far my script is like this

    var photosFolder = app.project.importFileWithDialog();
    var proj = app.project;

    var picName1 = "01.jpg"; // name of item you're looking for
    var picName2 = "02.jpg"; // name of item you're looking for
    var picName3 = "03.jpg"; // name of item you're looking for
    var picName4 = "04.jpg"; // name of item you're looking for
    var picName5 = "05.jpg"; // name of item you're looking for
    var picName6 = "06.jpg"; // name of item you're looking for

    var myPic1 = null;
    for (var i = 1 ; i <= app.project.numItems; i++){

    if (app.project.item(i).name == picName1){

    myPic1 = app.project.item(i);

    }

    if (app.project.item(i).name == picName2){

    myPic2 = app.project.item(i);
    }

    if (app.project.item(i).name == picName3){

    myPic3 = app.project.item(i);

    }

    if (app.project.item(i).name == picName4){

    myPic4 = app.project.item(i);

    }

    if (app.project.item(i).name == picName5){

    myPic5 = app.project.item(i);

    }

    if (app.project.item(i).name == picName6){

    myPic6 = app.project.item(i);

    }

    }

    var Comp1 = proj.items.addComp("Photo Comp1", 320, 180, 1, 08, 30);
    var LayersComp1 = Comp1.layers;

    var Pic2 = LayersComp1.add(myPic2);
    Pic2.threeDLayer=true;
    Pic2.property("Position").setValue([160,90,0]);
    Pic2.property("Scale").setValue([-100,100,100]);

    var Pic1 = LayersComp1.add(myPic1);
    Pic1.threeDLayer=true;
    Pic1.property("Position").setValue([160,90,-1]);

    var Comp2 = proj.items.addComp("Photo Comp2", 320, 180, 1, 08, 30);
    var LayersComp2 = Comp2.layers;

    var Pic4 = LayersComp2.add(myPic4);
    Pic4.threeDLayer=true;
    Pic4.property("Position").setValue([160,90,0]);
    Pic4.property("Scale").setValue([-100,100,100]);

    var Pic3 = LayersComp2.add(myPic3);
    Pic3.threeDLayer=true;
    Pic3.property("Position").setValue([160,90,-1]);

    var Comp3 = proj.items.addComp("Photo Comp3", 320, 180, 1, 08, 30);
    var LayersComp3 = Comp3.layers;

    var Pic6 = LayersComp3.add(myPic6);
    Pic6.threeDLayer=true;
    Pic6.property("Position").setValue([160,90,0]);
    Pic6.property("Scale").setValue([-100,100,100]);

    var Pic5 = LayersComp3.add(myPic5);
    Pic5.threeDLayer=true;
    Pic5.property("Position").setValue([160,90,-1]);

    var MainComp = proj.items.addComp("MainComp", 1280, 720, 1, 08, 30);
    var LayersMainComp = MainComp.layers;
    var FX = LayersMainComp.add(Comp1);
    FX.collapseTransformation = true;
    FX.threeDLayer=true;
    FX.property("Position").setValue([-850,0,0]);
    FX.property("Transform").property("X Rotation").setValueAtTime(3,0);
    FX.property("X Rotation").setValueAtTime(3.23,180);

    var echo = FX.Effects.addProperty("Echospace");
    echo.property("Instances").setValue(3);
    echo.property("X Offset").setValueAtTime(0,0);
    echo.property("X Offset").setValueAtTime(1,425);
    echo.property("Y Rotate").setValueAtTime(7,0);
    echo.property("Y Rotate").setValueAtTime(7.25,-90);
    echo.property("Transform Delay [sec]").setValue(0.3);

    No error massage at all…. BUT I’m hopeless searching the internet to find out how to write the code for clicking the “Repeat” button in Echospace.

    edit :
    after going deeper searching the net, there is a very complicated method to do that and I don’t think I’m able to handle it :(.
    Writing the above scripts alone already made my heartburn come.

    Is there another possible way to “pause” the script ?
    Maybe give an alert message with an OK button, let me manually click the “Repeat” button – click the OK button in the alert message, then the script continue ?

    Anyway, I want to say thank you once again for your help.
    Really appreciated.

    regards.

  • Dan Ebberts

    April 26, 2016 at 8:08 pm

    If your process requires manual interaction with Echospace, I think I’d do it with a script that has a UI. It would have a Build button which would launch the setup part of your script which would end with an alert dialog telling the user to click Repeat and then click the Continue button in your UI. A lot of work though…

    Dan

  • Reko Tomo

    April 27, 2016 at 7:49 am

    Hi Dan,

    I think I'd do it with a script that has a UI

    I think that’s the one that I found out in the internet.
    The complicated one :).

    A lot of work though...

    Yes indeed.
    As this is only my first try and is not a really important one, I don’t think I will bother to go that deep to write the script. I’m just interested in the basic process to code the script for After Effect.

    Thank you once again for your reply, Dan.

    regards.

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