var counter = 0
function layerCounter(inObj)
{
counter+= inObj.artLayers.length;
for( var i = 0; i < inObj.layerSets.length; i++)
{
counter++;
layerCounter(inObj.layerSets[i]);
}
return counter;
}
function getLayerCount()
{
function getNumberLayers()
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("NmbL") )
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getInteger(charIDToTypeID("NmbL"));
}
function getLayerType(idx)
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID("layerSection"));
ref.putIndex(charIDToTypeID( "Lyr " ), idx);
return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('layerSection')));
};
var cnt = getNumberLayers();
var res = cnt;
if(activeDocument.layers[activeDocument.layers.length-1].isBackgroundLayer)
{
var i = 0;
res++;
}
else
{
var i = 1;
};
for(i;i<cnt;i++)
{
var temp = getLayerType(i);
if(temp == "layerSectionEnd")
res--;
}
return res;
};
function main()
{
var layercount = layerCounter(app.activeDocument);
alert("Layer count = " + layercount);
}
main();