I’m trying to get the whole list of layers with
``` app.activeDocument.layers.length
```
however, this only works with pixel layers, it doesn’t count groups or adjustment layers, so how can I get the full length of all the layers counting groups and adjustment layers? Before with app.activeDocument.layers you would get the whole list including any type of layer but with it now you get only pixel layers, I’m I mistaken?
I remember when I was helping with DOM, the “Layers” was proxy object wrapping the array with instance of “Layer” inside. And the proxy was forwarding built-in array methods to its internal array. But all those methods can be optionally modified during that forwarding to behave in non-native way. Also, there were some extra methods. But I don’t see reason why it would do anything special with those built-in. Proxy and Reflect
DOM works as layer tree it gets layers at the level you are currently in. So in this case number of top level layers but not its children.
In action manager code layer set, frame tool and artboards have always two layers. One opening layer and one closing layer. But DOM has always only one.
You’re right — app.activeDocument.layers only returns top-level pixel layers now. To get all layers including groups and adjustment layers, you’ll need to loop through layerSets recursively. Something like:
function getAllLayers(doc) {
let layers = ;
for (let i = 0; i < doc.layers.length; i++) {
let layer = doc.layers[i];
layers.push(layer);
if (layer.typename === “LayerSet”) layers = layers.concat(getAllLayers(layer));
}
return layers;
}
LayerKind.GROUP refers directly to Photoshop internal layer kinds. While layer.typename === "LayerSet" refers to the class name in UXP DOM. LayerSet is better if you need to retrieve types for TypeScript or know the class of the object. While LayerKind is info about what is in PS. However, both should currently work fine in this case.
But in this specific condition case, isn’t it better to rely on the Ps internals, than on a class name/type, where typescript isn’t really even involved?
It depends on how Arboards or FrameTool could possibly be implemented in the future. Right now it is same in PS and UXP. There is no LayerKind.ARTBOARD