@J.C.C.1 wrote:
So far this seems like it works, Stephen, but I am curious if you know a good way to get the length of the selected acitve layers afterwards/
I was trying this, but had no luck.
var doc = app.activeDocument
var activeSelectionLength = doc.activeDocument.activeLayer.length
alert(activeSelectionLength)
There is no native method that I am aware of, perhaps there is some AM code... All of the ways that I know rely on "hacks", which is sometimes all that we have.
https://gist.github.com/hilukasz/03b17ee78414aadff995
This script dupes the selected layers into a temporary doc in order to count them. This script does not include any selected layer groups in the count, it is not bulletproof in my tests with nested groups inside groups, so YMMV:
selectedLayersLength();
function selectedLayersLength() {
// Dupe selected layers to temp doc
var idMk = charIDToTypeID("Mk ");
var desc302 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref122 = new ActionReference();
var idDcmn = charIDToTypeID("Dcmn");
ref122.putClass(idDcmn);
desc302.putReference(idnull, ref122);
var idNm = charIDToTypeID("Nm ");
desc302.putString(idNm, "", "TempLayerCountDoc", "");
var idUsng = charIDToTypeID("Usng");
var ref123 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref123.putEnumerated(idLyr, idOrdn, idTrgt);
desc302.putReference(idUsng, ref123);
var idVrsn = charIDToTypeID("Vrsn");
desc302.putInteger(idVrsn, 5);
executeAction(idMk, desc302, DialogModes.NO);
// Get the layer count
var layerCount = app.activeDocument.layers.length;
// Close the temp doc
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Count notification
alert(layerCount);
}
