thanks for the sample file, it helps a lot. So the issue with the previous script is that you have sublayers in the Front layer that were not being accounted for.
try this script to select both visible Groups and visible Sub Layers inside the Front layer
// Select visible items in a layer named "Front"
// also select items in sublayers if they are visible and not locked
var doc = app.activeDocument;
var targetLayer = null;
// Find the layer named "Front"
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers[i].name === "Front") {
targetLayer = doc.layers[i];
break;
}
}
if (targetLayer === null) {
alert("Layer 'Front' not found.");
} else {
// Deselect all first
doc.selection = null;
// Select all visible items in the "Front" layer
selectVisibleItems(targetLayer);
// also process sublayers if needed
for (var j = 0; j < targetLayer.layers.length; j++) {
if (targetLayer.layers[j].visible && !targetLayer.layers[j].locked) {
selectVisibleItems(targetLayer.layers[j]);
}
}
alert("Selected visible items in 'Front' layer.");
}
function selectVisibleItems(layer) {
for (var i = 0; i < layer.pageItems.length; i++) {
var item = layer.pageItems[i];
if (item.hidden === false && item.locked === false) {
item.selected = true;
}
}
}