I have a quickly written script here. The issue comes when you do have layer groups because they are not indexed in order from bottom to top when you expand the group. All the top level layers (and groups) are indexed first, then the next level of groupings are indexed, and so on. So if you have some like.....from bottom to top.....Layer 0, Layer 1, Group 0 (Layer 8, Layer 9, Layer 10), Layer 2, Group 1 (Layer 4, Layer 5, Layer 6), Layer 3 then the document layers array will index them [Layer 0, Layer 1, Group 0, Layer 2, Group 1, Layer 3, Layer 8, Layer 9, Layer 10, Layer 4, Layer 5, Layer 6] so it does get complicated when you try to involve levels of the layer groupings. I can be done, though.
function chrToTID(c) {
return app.charIDToTypeID(c);
}
function strToTID(s) {
return app.stringIDToTypeID(s);
}
function mLaySelect() {
lays=prompt("Number of layers to add",10,"Layer Selections");
add=Number(lays)
cid=app.activeDocument.activeLayer.itemIndex; //gets the index number of the current layer.
tid=app.activeDocument.layers.length; //gets the layer length within the document
tdl=cid+add; //calculates the highest desired layer to select.
tsl=Math.min(tdl,tid); //sets the highest layer to either the one desired if possible of the highest layer if not.
el=tid-(cid+add); //gets layers[i] index number so we can get the name of the last layer.
topLayer=app.activeDocument.layers[el]; //top most layer. We need the name for the continuous selection.
$.writeln(topLayer.name+"el="+el+" lays="+lays+" cid="+cid+" tid="+tid+" tdl="+tdl+" tsl="+tsl);
var AD = new ActionDescriptor();
var REF = new ActionReference();
REF.putName(chrToTID('Lyr '), topLayer.name);
AD.putReference(chrToTID('null'), REF);
AD.putEnumerated(strToTID("selectionModifier"), strToTID("selectionModifierType"), strToTID("addToSelectionContinuous"));
AD.putBoolean(chrToTID('MkVs'), false);
var AL = new ActionList();
for (i=cid;i<tsl;i++) {
AL.putInteger(i);
$.writeln("i="+i);
if (i>100) break;
}
AD.putList(chrToTID('LyrI'), AL);
executeAction(chrToTID('slct'), AD, DialogModes.NO);
}
mLaySelect();