Duplicate multiple layers with the same name
I have a Text and Solid layer that are labelled Bar 1. I want to duplicate both at the same time. I know I can highlight and hit Ctrl + D, but I am writing a script where I might as well have it as a part of my button onClick function. So that the layers duplicate and then using the script apply new data to these.
I can duplicate using this.
var myComp = app.project.activeItem;
myComp.layer("Bar 1").duplicate();
But it only recognises the first Bar 1 layer. So I tried a for loop.
var myComp = app.project.activeItem;
for ( var i = 1; i <= myComp.numLayers; i++){
var myComp = app.project.activeItem;
myComp.layer("Bar 1").duplicate();
};
this worked and crashed after effects as it wouldn't stop duplicating ![]()
So I included a break.
var myComp = app.project.activeItem;
for ( var i = 1; i <= myComp.numLayers; i++){
var myComp = app.project.activeItem;
myComp.layer("Bar 1").duplicate();
break;
};
But now I am back to square one, it will only do the first one in the chain rather than both.
I know I'm missing something silly, but I was hoping someone could point it out please.
