get layer out of array by name
Hi everybody!
I know, it is a very basic thing.
But I searched the whole day for a solution. Now I hope somebody laughing out loud about and gives me a hint..
. ![]()
If I collect all layers in an array (some are on the hoghest level, others in layser sets) and wanted to get one of them out of the array searching for its name how I can do this?
var myDoc = app.activeDocument;
var allLayers = [];
var allLayers = collectAllLayers(myDoc, allLayers);
function collectAllLayers (myDoc, allLayers){
for (var i = 0; i < myDoc.layers.length; i++){
var theLayer = myDoc.layers;
if (theLayer.typename === "ArtLayer"){
allLayers.push(theLayer);
}else{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
alert(allLayers[4]);
If I search by the key it works. But you never know on which position the layer is.
I need the layer as an object to move it somewhere else.
