Skip to main content
maninthebox390
Participant
October 23, 2015
Question

need script to export all layer names into an excel sheet or text file.

  • October 23, 2015
  • 3 replies
  • 14589 views

are there any scripts to export layer names into an excel sheet or a text file?

This topic has been closed for replies.

3 replies

Participating Frequently
May 29, 2023

Hi. is there a way to skip the Hue/Saturation layers from the list, because they are getting added too?

Thanks,

Mukul

Stephen Marsh
Community Expert
Community Expert
May 29, 2023
quote

Hi. is there a way to skip the Hue/Saturation layers from the list, because they are getting added too?

Thanks,

Mukul


By @chandubhau

 

What method are you using, the one from @jazz-y or another one?

Participating Frequently
May 29, 2023

Yes, the one from @jazz-y .

Stephen Marsh
Community Expert
Community Expert
May 13, 2017

This is also possible with ExifTool using the following command:

exiftool -Photoshop:LayerNames PATH-TO-FILE-or-FOLDER

Which would output the following (which may be a little cryptic, see the screenshot below for a visual):

Color Fill 1, </Layer group>, Layer 0, Layer 1, Layer 2, Layer 3, Group 1, Layer 4, Invert 1

For an Adobe Illustrator .AI file, the command would be:

exiftool -a -XMP-egLayL:LayersName PATH-TO-FILE-or-FOLDER

natrev
Legend
October 23, 2015

Hi maninthebox390,

Try this Code..... and Big Thanks to c.pfaffenbichler.

-yajiv

#target photoshop

var theLayers = collectLayers(app.activeDocument, []);

////// function collect all layers //////

function collectLayers (theParent, allLayers) {

      if (!allLayers) {var allLayers = new Array}

      else {};

        var theNumber = theParent.layers.length - 1;

      for (var m = theNumber; m >= 0;m--) {

          var theLayer = theParent.layers;

        // apply the function to layersets;

          if (theLayer.typename == "ArtLayer") {

          OutFoldCSV("~/Desktop",theLayer.name);

          }

          else {

          allLayers = (collectLayers(theLayer, allLayers))

        // this line includes the layer groups;

          OutFoldCSV("~/Desktop/Layer_Data",theLayer.name);

          }

      };

      //return allLayers

  };

     function OutFoldCSV(App_Path,Layer_name){

        var outfolder = new Folder(App_Path)

            if (outfolder.exists == false){

                outfolder.create();

                var myLogFile = new File(outfolder + "/LayerRef.xls");

                myLogFile.open("a", undefined, undefined)

                myLogFile.write(Layer_name);

                myLogFile.write("\n");

            }

            else{

                var myLogFile = new File(outfolder + "/LayerRef.xls");

                myLogFile.open("a", undefined, undefined)

                myLogFile.write(Layer_name);                

                myLogFile.write("\n");

            }

    }

Participant
February 14, 2021

I have a project I am working on that has almost 1400 layers and I need help with a script that will export the layer names to a text file (preferably) or an .xls file.

I tried the code in this link but it doesn't work... may just need some mods. (It was something I found on the web from 2015).  

Can anyone help me with this?

 

need script to export all layer names into an excel sheet or text file.

 

Thanks in advance!

Scott

Known Participant
August 29, 2022

Since this post, I have managed to write a script to both copy to the clipboard and also to save a csv of top-level layers names.

 

// Layer Names to CSV and Clipboard CR List.jsx
// Stephen Marsh, 2021
// Useful for creating a layer visibility data set for Data Driven Graphics / Variables

// Loop over top level layers and layer sets
var lyrCount = app.activeDocument.layers.length;
var lyrArray = [];
for (var i = 0; i < lyrCount; i++) {
    lyrArray[i] = app.activeDocument.layers[i].name;
}

// Layers to list and CSV
var list = lyrArray.toString().replace(/,/g, '\r');
var csv = lyrArray;

// Copy layer list to clipboard
var d = new ActionDescriptor();
d.putString(stringIDToTypeID('textData'), list);
executeAction(stringIDToTypeID('textToClipboard'), d, DialogModes.NO);

// Create a text file of the layer list
var textFile = new File('~/Desktop' + '/' + 'layerList.csv');
// r for read mode - w for write mode - a for append - e for edit
textFile.open('w');
textFile.encoding = 'UTF-8';
textFile.write(csv);
textFile.close();

// End of script notifications
app.beep();
alert('Top level layer list copied to clipboard and saved to .csv on desktop');

Can you make your script works with multiple artboards in one PSD document? I'm making banners on different artboards and on the end I need text data with all layers names. Your script works, but it's copying only artboard name and nothing deeper. Plz help