Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

New Here ,
Oct 22, 2015 Oct 22, 2015

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

4.2K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 22, 2015 Oct 22, 2015

Copy link to clipboard

Copied

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");

            }

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

This is a useful working script. I would like to customize the script by adding the file name to the list of layers in the xml file. Can someone provide guidance to achieve this result.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Photoshop is not a file editor and new documents have no associated files till you save one.  Do you want the full file path and name and extension?

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Just the file name and extension in the xml document if possible.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Adding the before the first if may work.  Id the document is nor saved it will just add the document mane without any extension

      OutFoldCSV("~/Desktop",app.activeDocument.name);
JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

OutFoldCSV("~/Desktop",app.activeDocument.name);  replaces the layers names in the xls with the document name.

When placed before the first if statement it prints the document name before each layer name in the xls.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Before the first if...

#target photoshop

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

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

function collectLayers (theParent, allLayers) {

      OutFoldCSV("~/Desktop",app.activeDocument.name); //<---------------------------------------------------------------------------------

      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");

            }

    }

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Placing the function call  OutFoldCSV("~/Desktop",app.activeDocument.name); before the first if statement prints the document name in the xls. However if the document has layer groups it prints the document name  folder name. Is there a way to by pass the layer groups?


Screen Shot 2015-10-23 at 4.17.54 PM.png Screen Shot 2015-10-23 at 4.20.04 PM.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

I did not see that the function collectLayers was being used recursively. The statement I added needs to be outside that function.

#target photoshop

OutFoldCSV("~/Desktop",app.activeDocument.name);

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");

            }

    }

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2015 Oct 23, 2015

Copy link to clipboard

Copied

Yes, this works great. I modified the docPath to save the Layer_Data directory and LayerRef.xls file in the same directory as the source files which the script process.

The final issue to consider is adding the file name to the Layer_Data/LayeRef.xls which lists the layer groups from the source file.

Below is the script with the docPath modifications.

Thanks for your help!

#target photoshop

var thedoc = app.activeDocument;

var docPath = thedoc.path;

OutFoldCSV(docPath,app.activeDocument.name);

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(docPath,theLayer.name);

          }

          else {

          allLayers = (collectLayers(theLayer, allLayers))

          // this line includes the layer groups;

          OutFoldCSV (docPath+"/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");

      }

  };

// source: https://forums.adobe.com/message/8100899#8100899

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Hi Guys, should this still work? I am getting an error message

Error 1302: No such element

Line :13

-> var thenumber = the Parent.layers.length - 1;

 

Do I take this from the web and save as a 'js' file and run through photoshop?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2016 Jun 13, 2016

Copy link to clipboard

Copied

Hi, does this work for Illustrator too? thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

I just tried this in illustrator and it works ... kind of ...

For some reason, the script only outputs the first (top) layer and second (nested) layer. I'm not too good at javascript so I don't really know how to get it to output all layers and sub layers.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

It's better to ask same question in that topic instead of 'duplicating' existing one.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Thanks for the reprimand but still doesn't help.  Total novice at this, just trying to get friendly help!

Sorry if I duplicated a question...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Unfortunately it's my ACP role to say it when there's need 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Hard for me to script... Easy for me to write a single line of code for ExifTool:

 

 

exiftool -csv -ext .psd -LayerNames 'Mac OS Path to PSD/Input Folder' > 'Mac OS Path to/output file.csv'

 

 

(Note: Win OS uses straight double quotes around file paths that contain spaces) 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Thanks!  Will give this a try and assuming it works on PC versionas well.  Much appreciated!

 

 

Worked great!  Thanks again for the help!

Best-

S

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Great, thanks for the thanks! Depending on end-use, further text/string manipulation may be required.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

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');

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

LATEST

Here is an alternate way to get data to the Clipboard in Photoshop (this demo copies the filename)

#target photoshop

copyFilename();

function copyFilename(){
    try{
        if(documents.length > 0){
            var originalDialogMode = app.displayDialogs;
            app.displayDialogs = DialogModes.ERROR;
            var docRef = activeDocument;
            app.displayDialogs = originalDialogMode;
            }
        var cmd;
        var isWindows;
        isWindows = $.os.indexOf('Windows') != -1;
        if(isWindows){
            cmd = 'cmd.exe /c cmd.exe /c "echo ' + docRef.name + '| clip"';
            }
        else{
            cmd = 'echo ' + docRef.name + ' | pbcopy';
            }
        app.system(cmd);
        }
    catch(e){
        alert(e + e.line);
        }
    }

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 13, 2017 May 13, 2017

Copy link to clipboard

Copied

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

layers.png

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

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines