13 Replies Latest reply on May 13, 2017 4:42 AM by Stephen_A_Marsh

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

    maninthebox390

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

        • 1. Re: need script to export all layer names into an excel sheet or text file.
          natrev Level 3

          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[m];

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

                      }

              }

          • 2. Re: need script to export all layer names into an excel sheet or text file.
            ojodegato Level 1

            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.

            • 3. Re: need script to export all layer names into an excel sheet or text file.
              JJMack Most Valuable Participant

              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?

              • 4. Re: need script to export all layer names into an excel sheet or text file.
                ojodegato Level 1

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

                • 5. Re: need script to export all layer names into an excel sheet or text file.
                  JJMack Most Valuable Participant

                  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);
                  • 6. Re: need script to export all layer names into an excel sheet or text file.
                    ojodegato Level 1

                    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.

                    • 7. Re: need script to export all layer names into an excel sheet or text file.
                      JJMack Most Valuable Participant

                      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[m];

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

                                  }

                          }

                      • 8. Re: need script to export all layer names into an excel sheet or text file.
                        ojodegato Level 1

                        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

                        • 9. Re: need script to export all layer names into an excel sheet or text file.
                          JJMack Most Valuable Participant

                          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[m];

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

                                      }

                              }

                          • 10. Re: need script to export all layer names into an excel sheet or text file.
                            ojodegato Level 1

                            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[m];

                                      // 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

                            • 11. Re: need script to export all layer names into an excel sheet or text file.
                              Sangsiv

                              Hi, does this work for Illustrator too? thanks

                              • 12. Re: need script to export all layer names into an excel sheet or text file.
                                Gary Vey Level 1

                                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.

                                • 13. Re: need script to export all layer names into an excel sheet or text file.
                                  Stephen_A_Marsh Adobe Community Professional

                                  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