9 Replies Latest reply on Sep 11, 2015 11:13 AM by Chuck Uebele

    Export coordinates

    sdanckaarts

      We have 10.000 PSD files which contains several layers. The PSD contain product photo's.

       

      In 1 of those layers, a red dotted line has been created ( to indicate the area where we want to put a sticker ). Is it somehow possible to export information from those PSD files in which we can find the coordinates of those red dotted lines and their heigth/width info ?

        • 1. Re: Export coordinates
          Chuck Uebele Adobe Community Professional & MVP

          Yes, with scripting. Are all those layers with the line named the same? I' moving your post to the Photoshop Scripting forum.

          • 2. Re: Export coordinates
            sdanckaarts Level 1

            Thanks Chuck. I don't think the layers are all named the same, they have a description of the specific sticker which needs to be on the product most likely.

             

            For now, I think I can move on. I need to dive into photoshop scripting and get some idea of its options and how to achieve it. Just needed to know whether it was feasible at all.

             

            thanks again !

            • 3. Re: Export coordinates
              Chuck Uebele Adobe Community Professional & MVP

              It is doable. Keeping the layers with the same name would be ideal.

              • 4. Re: Export coordinates
                KoMaruyama Adobe Community Professional

                Is there a resource for the script that would export Photoshop layer coordinates (Upper Left corner) to XML / TXT?

                How does it handle group folders?

                 

                Photoshop has no problem handing off to After Effects, but I'd like to use Generate/Extract with a corresponding XML document to match positions.

                 

                Is it possible? Where would I start looking?

                • 5. Re: Export coordinates
                  Chuck Uebele Adobe Community Professional & MVP

                  Ko, I'm not sure if there is a current resource for that, but it would be fairly easy to create. It would just be a matter of cycling through the layers, detecting which ones have bounds, then writing to either a text file or an XML file.

                  • 6. Re: Export coordinates
                    KoMaruyama Adobe Community Professional

                    Thanks Chuck.  Any good reference sites to start with?

                     

                    (I'm a little surprised that nothing comes up on the radar for this one.  I figure it'd be something that everyone would want with the export)

                    • 7. Re: Export coordinates
                      Chuck Uebele Adobe Community Professional & MVP

                      Ko, Here's a script that will write a text file in the same folder as the image file. You can adjust what is in the text file by editing the line 22.

                       

                      #target photoshop
                      
                      var doc = activeDocument;
                      var docPath = doc.path;
                      var XY = '';
                      var txtDoc = new File(doc.path + '/' + doc.name.split('.')[0]+'.txt');
                      doc.activeLayer = doc.layers[0];
                      getXY (doc)
                      writeFile (txtDoc, XY)
                      
                      function getXY(lSet){
                      
                          for(var i=0;i<lSet.layers.length;i++){
                              doc.activeLayer = lSet.layers[i];
                              if(doc.activeLayer.typename == 'LayerSet'){
                                  if(doc.activeLayer.layers.length>0){
                                      getXY (doc.activeLayer)
                                      }
                                  }
                              else{
                                  //format the following line how you want your text document
                                  XY += doc.activeLayer.name + ': X= ' + doc.activeLayer.bounds[0] + ' Y= ' + doc.activeLayer.bounds[1] + '\n';
                                  }         
                              };//end loop
                          };
                      
                      function writeFile(file, txt) {
                              file.encoding = "UTF8";
                              file.open("w", "TEXT", "????");
                              //unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF"
                              file.write("\uFEFF");
                              file.lineFeed = "unix";
                              file.write(txt);
                              file.close();
                          };
                      
                      • 8. Re: Export coordinates
                        KoMaruyama Adobe Community Professional

                        Amazing Chuck. 

                        Photoshop scripting is still all greek to me, but I'll give it a whirl.

                         

                        Thank you so much for the inline remarks.  I try to put remarks into my After Effects scripts/expressions whenever I can - and now I realize how helpful those really are.

                         

                        #Learning!

                        • 9. Re: Export coordinates
                          Chuck Uebele Adobe Community Professional & MVP

                          I didn't include getting group names, and it will capture adjustment layers, even though their coordinates will be 0,0. It all can be adjusted.