Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Loop through project panel and select comp

  • Loop through project panel and select comp

    Posted by Hus Yaralioglu on January 6, 2019 at 3:20 am

    I am new to scripting and I would love some help and advice!

    I have a template project that requires me to constantly replace the image in my comp. Using Replace Footage is tedious as I constantly have to navigate folders.

    I have created a script that opens a dialog window pointing to a specific folder, and when I import my new image it automatically replaces the one currently in the comp. The problem is the comp index sometimes changes due to the image filenames being different, causing my script to fail.

    Please could someone help me change the first line of code so that it loops through the project panel and automatically selects the comp?

    // access the comp
    var theComp = app.project.item(2);

    // get the existing image layer in the comp
    var theImageObject = theComp.layers[2];

    // bring up folder to import the new image that I'd like to use
    var newArtwork = new Folder("C:/Users/PC/Pictures").openDlg("Import File");

    // import new image
    var newImport = app.project.importFile (new ImportOptions (newArtwork));

    // replace the existing image with the new one
    theImageObject.replaceSource(newImport, true);

    Dan Ebberts replied 7 years, 8 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 6, 2019 at 6:19 am

    Do you know the name of the comp? That’s probably the easiest way to find a comp by looping through the project items. An alternative would be to use app.project.activeItem if you could assume that the comp is currently the item with focus.

    Dan

  • Hus Yaralioglu

    January 7, 2019 at 7:46 am

    Well I am also looking to automate the render queue and output filename which will be driven by the comp name, so that won’t work as the comp name will change in tandem with each image change.

    But I actually thought of a simple workaround! I have placed my comp in a folder called #comp. This ensures the folder is always index 1 and the comp is always index 2, regardless of what the image filename turns out to be, as # always supersedes numbers and characters.

  • Dan Ebberts

    January 7, 2019 at 2:18 pm

    Another thing you could do is put an identifying comment in the comp’s comment field.

    Dan

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