Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Replacing layers with comps Script

  • Replacing layers with comps Script

    Posted by Igor Stikic on January 5, 2016 at 12:47 pm

    Hi,

    i need to frequently change 100+ layers in several comps with compositions. (Alt + Hold and move is to slow)The Layers and the comps are the same name but I can’t figure out how to wright that script. I create simple project with 6 items to replace for example. So please help me out.

    If you look in screenshot I need in Comp “Portfolio 1080p” to replace Layers “Photo 1”, “Photo 2″… with Comps marked with red. Problem is that “Photo 5” and “Photo 6” are in different comps, and “Photo 1” repeat it self.

    Thank you in advance!

    var projectItems = app.project.items;
    var i = 1;
    var j = 1;
    var x = 1;
    var str= '';
    for(i=1; i < projectItems.length; i++){
    var item = projectItems[i].name;
    if(item.name == "Portfolio 1080p"){
    alert(1);
    for(j=1; j <= 7; j++){
    var newItem = null;
    if(item.layer(j).name != "5 Folio"){
    if(item.layer(j).name != "6 Folio"){
    alert(2);
    for(x =1; x < projectItems.length; x++){
    if(item.layer(j).name == projectItems[x].name){
    alert(3);
    newItem = projectItems[x];
    item.replaceSource(newItem, false);
    }
    }
    }
    }
    }
    }
    }

    Igor Stikic

    Thomas Patrick replied 8 years, 8 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 5, 2016 at 6:33 pm

    I think I’d do it like this:


    function getComp(theName){
    for (var i = 1; i <= app.project.numItems; i++){
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name == theName)){
    return app.project.item(i);
    }
    }
    return null;
    }

    function main(){
    var myComp = getComp("Portfolio 1080p");
    if (myComp == null){
    alert ("Can't find comp 'Portfolio 1080p'");
    return;
    }
    var photoComp;
    var photoCompName;
    for (var i = 1; i <= myComp.numLayers; i++){
    photoCompName = myComp.layer(i).name.split(".")[0];
    photoComp = getComp(photoCompName);
    if (photoComp == null){
    alert ("Can't find comp '" + photoCompName + "'");
    return;
    }
    myComp.layer(i).replaceSource(photoComp,false);
    }
    }

    main();

    Dan

  • Igor Stikic

    January 6, 2016 at 10:21 am

    Thank you very very much!

    Igor Stikic

  • Thomas Patrick

    December 11, 2017 at 5:17 pm

    Hi There,

    I’m trying to do something similar to Igor but still having difficulty…

    I need to replace old comps with newer comps as layers in multiple compositions. I’ve included an annotated screenshot to explain exactly what I mean. Essentially I’ll have a folder full of “_OLD” comps and another folder full of “_NEW” comps. I’ll also have a folder full of comps that contain the “_OLD” comps as layers.

    What I’m trying to do (with varying degrees of success…) is replace the “_OLD” layers with the “_NEW” layers inside the “REPLACED” comps. But I’ve been doing it by index and running into problems when the “REPLACE” comps have additional layers.

    I think I need to:
    -loop through the all of the “REPLACED” comps (Currently in a MON folder) to look for layerscomps the contain “_OLD”
    -For layers that contain “_OLD” check to see if there is a corresponding “_NEW” comp in the “NEW_COMPS” folder
    -If the layer exists, replace the “_OLD” layer in the “REPLACED” comp, else alert(“CANT FIND COMP x…”)

    I think this logic would replace everything correctly but my JS is apparently atrocious…

    Thanks for any help/tips!

    Tom

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