Answered
How to improve this script performance? Get all layers id
I use this script to get all layer ids, then use the array to select the next or previous layer based on the id, but the performance is too slow. Is there any way to improve this script? Please help!
function getAllLayerIds(layers = app.activeDocument.layers, layerIdArray = []) {
for (const layer of layers) {
layerIdArray.push(layer._id); // Push the layer's ID
// Check if the layer has children (sublayers)
if (layer.layers && layer.layers.length > 0) {
getAllLayerIds(layer.layers, layerIdArray); // Recursive call
}
}
return layerIdArray;
}
