arrayssplitphotoshopextendscript

how can I retrieve Photoshop artlayer names from specific sub-layerset into an array?


I have a Photoshop PSD document which has a layerset named “Flags“. “Flags” has a sub-layerset called “LEFT-Flags“ which itself contains artlayers, each with a national flag image. The number of these artlayers is currently around 40 - but will increase over time.

As an ExtendScript newbie, may I ask how - in ExtendScript - can I extract the NAMES of each of the artlayers to an array please?


Solution

  • Basically it can be done this way:

    var layers = app.activeDocument
        .layerSets['Flags']
        .layerSets['LEFT-Flags']
        .artLayers;
    
    var names = [];
    for (var i=0; i<layers.length; i++) names.push(layers[i].name);
    
    // put the names into a txt file and open the file
    var f = File(Folder.temp + '/layers_names.txt');
    f.open('w');
    f.encoding = 'UTF-8';
    f.write(names.join('\n'));
    f.close();
    f.execute();
    

    The array names will contain the names.

    But I don't know what you want to do with this array. Do you mean to save it as a TXT file?