Scripting : get number of layers with Action Manager. : Is this a bug ?
So... consider the following function.
function getNumberOfLayers() {
// For debugging purposes
var start = new Date().getTime();
var ref4 = new ActionReference();
ref4.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref4);
// For debugging purposes
var end = new Date().getTime();
alert(end-start);
return docDesc.getInteger(stringIDToTypeID("numberOfLayers"));
}
This returns the number of layers in a document. Notice I added a few debugging lines to get the time it takes to execute.
When the function is called while a layer's RGB channel is selected (the "ArtLayer"), it takes much more time to execute, than when the layer's mask is selected. It really depends on the document, but I've seen numbers like this :
Time to execute (in milliseconds) :
- With the layer's RGB channel selected : 250ms
- With the layer's mask selected : 10ms
Of course, 250ms isn't great at all, and it makes a noticeable difference... but I'm wondering what might be going on here... it just doesn't make sense to me.
Also... I had trouble with another similar function (a function detecting if there was a background layer or not), and stumbled on this page. It looks like accessing the "Document" through action manager code might not be that efficient...
So...
1 - Anyone has any clue about what is going on ?
2- Anyone has a better, faster way to get the number of layers in a document ?
Many, many thanks folks.
J
