@c.pfaffenbichler
Yes sir
The group layer is excluded from the selection
Why are the layers inside the group not excluded as the group was excluded?
- This is a suggestion
Another suggestion
- I want when selecting a group by name, all layers within the group are also selected
Is this simple or complicated
Your descriptions are really hard for me to comprehend.
Screenshots that illustrate what you actually want to achieve might be helpful.
The following Script would select all Layers except the top level Group of a certain name and the Layers within that Group (see screenshots).
I am not sure if this is what you want to achieve, though.


// select all layers except the group of a certain name and the ones in that group;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
var theName = "xxx";
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("numberOfLayers"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
var theLayers = getLayersAndItsParentsIndexAndID(theName);
var numberOne = theLayers[theLayers.length-1][0][1] - 1;
var numberTwo = theLayers[0][theLayers[0].length-1][1] + 1;
var add = false;
for (var m = 0; m < numberOne; m++) {
selectLayerByIndex(m, add);
var add = true;
};
for (var n = numberTwo; n <= theNumber; n++) {
selectLayerByIndex(n, true);
};
};
////////////////////////////////////
////// collect layers and their parents if the top level group has a specific name //////
function getLayersAndItsParentsIndexAndID (folderName) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// anumber is intended to keep track of layerset depth;
var aNumber = 0;
var theArray = new Array;
//var theGroups = new Array;
// work through layers;
for (var m = theNumber; m >= 0; m--) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
//var hasLayerMask = layerDesc.hasKey(charIDToTypeID("Usrs"));
var thisArray = [[theName, m, theID]];
////////////////////////////////////
// if group start:
if (layerSet == "layerSectionStart" && isBackground != true/* && theName == folderName*/) {
if (aNumber == 0) {var setArray = [[theName, m, theID]]}
else {
// include groups in array;
for (var o = setArray.length - 1; o >= 0; o--) {thisArray.push(setArray[o])};
// set array;
setArray.push([theName, m, theID])
};
//theGroups.push([theName, m, theID]);
// add to mark group;
aNumber++
};
// if group end;
if (layerSet == "layerSectionEnd" && isBackground != true) {
// subtract to mark end of group;
aNumber--;
if (aNumber == 0) {var setArray = []}
else {setArray.pop()}
};
// if neither group start or end;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
// if anumber is 0 layer is top level;
if (aNumber != 0) {
for (var o = setArray.length - 1; o >= 0; o--) {thisArray.push(setArray[o])};
// check the to plevel folder name;
if (thisArray[thisArray.length-1][0] == folderName) {
theArray.push(thisArray)
}
};
};
////////////////////////////////////
} catch (e) {};
};
// the results;
return theArray
};
////// by mike hale, via paul riggott //////
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
try {
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
} catch (e) {}
};