K basically I need to write a photoshop script that iterates through the selected layers and retrieve some information about them.
if I can get an array of the selected layers I will be fine, I know how to do the rest, but getting that array is been a headache on its own.
I know the document holds something like "activeLayers" but I get lost how to deal with levels and sublevel layers.
All the layers are in a group, so if its easier, if I can get every layer in a group that would be great too :D
Thanks for any tips on this.
This will get you the selected layers
Source: https://github.com/kynd/photoshopScripts/blob/master/Rename%20Selected%20Layers/Rename%20Selected%20Layers.jsx
Bravo's code works except it fails with an error when no layers are selected, so I tweaked it to remove the error and simply return an empty array:
Simply wrapping the code in a try/catch block didnt work, so I also changed:
to
and that made the runtime error go away.
You'll need to check out the 'ArtLayers' and 'LayerSets' objects. The following snippet will get all the layers in the first group within a document:
But since each of your groups can contain other groups, you may have to recursively loop through all of them to get all your layers depending on your use case.
I highly recommend checking out the xtools library. It has a nice function 'Stdlib.getLayersList' that will allow you to get the all the layers recursively from nested groups (plus a whole lot of other great stuff). Get the library here.