I’m assuming that you want paF to be an array of face-related layers?
This code loops through all selected layers.
If it finds a HEAD layer, it sets paH to that layer. (Note that if you have multiple HEAD layers, no error will be thrown and the script will just use the last HEAD layer in the selection.)
If it finds a FACE layer, it pushes that layer onto the paF array. paF begins as a null layer, and then each detected FACE layers is added to the array. Note that this array has its own indexing, not necessarily related to the comp’s index — though, of course, you can always look at paF[i].index to get that info.
var layersList = app.project.activeItem.selectedLayers;
var checkHAT = "HAT";
var checkGAP = "GAP";
var checkHAIR = "HAIR";
var checkEAR = "EAR";
var checkNOSE = "NOSE";
var checkMOUTH = "MOUTH";
var checkEYE = "EYE";
var checkCHEEK = "CHEEK";
var checkHEAD = "HEAD";
var paH = 0;
var paF = [];
// iterate through all selected layers. Find the HEAD layer, and build an array of FACE-related layers.
for (i = 0; i < layersList.length; i++) {
var child = layersList[i].name;
/* check HEAD */
if (child.indexOf(checkHEAD) > -1) {
paH = layersList[i];
}
/* check FACE*/
else if ((child.indexOf(checkHAIR) > -1) ||
(child.indexOf(checkEAR) > -1) ||
(child.indexOf(checkMOUTH) > -1) ||
(child.indexOf(checkEYE) > -1) ||
(child.indexOf(checkCHEEK) > -1) ||
(child.indexOf(checkGAP) > -1) ||
(child.indexOf(checkHAT) > -1)) {
paF.push(layersList[i]);
}
} //loop out
if (paH == 0) {
alert("No " + checkHEAD);
} else if (paH != 0) {
var t = "Head layer:\n" + paH.name + "\n\nList of face layers (paF):\n";
for (i = 0; i < paF.length; i++) {
t += paF[i].name + "\n";
}
alert(t);
}