does not gives the name if that layer is inside of a group.
it was working fine but stop working
it only shows the name if the layer is out of group
how do i do the same in order to fix my problem?
I see that in the Layers panel there is 2 layers inside of a group and two layers out and inside of the class the activeDocument.layers only see the out layers.it was not like that before.
New Layers collection, the old layerTree object is now called layers but as a collection using the JavaScript Proxy object. See below for introduction of collections. The old layers behavior is no longer part of the DOM. Most scripts can be updated to replace layerTree with layers . A document and a layer, if the layer kind is group, will have a valid layers collection. A pixel layer will have null for the layers property. A collection has the same semantics as an Array. The additional ExtendScript routines of add and getByName are also available. Use LayerKind.GROUP on a layer to see if any layers are available.
GroupLayer has been removed. Use activeLayer.kind === LayerKind.GROUP instead.
I already read that information and as I commented if you do the example you will see that.
With Ap2 which was the new thing I did, the same code was workin but after the change it only sees the layers that are outside a group. Test and confirm. please
Why would I test and confirm? Both you and docs say the same, so I trust that is the case. As I mentioned, you will probably have to implement full tree getter yourself. Or maybe someone already has it and will share
This is what I mean. Before updating it worked fine.
As seen in the example, it only shows the name of the group and the black Layer that is outside, but the red one does not see it. if I compile the class it only has 2 elements in the array when before it showed everything.
can someone show me what to do?
and thanks for replying.
You’re going to need to write a recursive getter function that loops through each top level layer as you are already doing, checking if it is a group layer or not, then looping though any child layers if found (and checking if they’re group layers, etc, etc). All the while you push the found layers to an array which the function’s return value.
// example assumes all layers are group layers
const topLevelLayers = app.activeDocument.layers;
for (const topLayer of topLevelLayers) {
const childLayers = topLayer.layers;
for (const childLayer of childLayers) {
const moreChildLayers = childLayer.layers;
}
}
Quick suggestion - when you use a loop (forEach in your example) you are passing each individual enumerable into the curly braces one at a time so it’s best to use singular rather than plural terminology. it’ll make your code easier to read.
// "layer" rather than "allLayers"
// because once inside the loop it is only one layer at a time
// "for each layer... do stuff..."
app.activeDocument.layers.forEach(layer=> {
if(layer.kind == “group”) {
const al = layer.layers[1].name;
app.showAlert(al);
}
});