-
script to search for a layer name and return it’s index
I am trying to write a bit of code I can call to search within a composition for a layer name and return the layer’s index, so I can then perform some actions on it.
The following shows that the variables have the expected values when running, but once it gets back to the code it was called from the layIndex variable shows as undefined.
How do I get the layIndex value to be returned?
Thanks
function sLN(compToSearch, layNS, layIndex){
// compToSearch: name of composition to search (a global variable) , layNS: the layer name I'm searching for (a global variable), layIndex: the index of the layer that was searched for
var K=compToSearch.numLayers, layer;
for (var k = 1; k<=K; k++) {
if (compToSearch.layer(k).name === layNS) {layer = compToSearch.layer(k);
break;
};
layIndex = k;
}