ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Replacing layers with comps Script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Igor Stikic
Replacing layers with comps Script
on Jan 5, 2016 at 12:47:22 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 &lt; projectItems.length; i++){
var item = projectItems[i].name;
if(item.name == "Portfolio 1080p"){
alert(1);
for(j=1; j &lt;= 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 &lt; projectItems.length; x++){
if(item.layer(j).name == projectItems[x].name){
alert(3);
newItem = projectItems[x];
item.replaceSource(newItem, false);
}
}
}
}
}
}
}


Igor Stikic


Return to posts index


Dan Ebberts
Re: Replacing layers with comps Script
on Jan 5, 2016 at 6:33:35 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



Return to posts index

Igor Stikic
Re: Replacing layers with comps Script
on Jan 6, 2016 at 10:21:34 am

Thank you very very much!

Igor Stikic


Return to posts index


Thomas Patrick
Re: Replacing layers with comps Script
on Dec 11, 2017 at 5:17:13 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]