3 Replies Latest reply on Jun 20, 2017 7:59 PM by JJMack

    Export layer coordinates, layer width and height?

    nvega

      I have need for a script that exports a txt file that contains each layer's coordinate and the pixel width and height.

       

      I found this excellent script from guru Chuck, works great but no pixel width and height.

      Re: Export coordinates

       

      and this post from Paul works, too, but again no pixel width and height.

      Re: Export co-ordinates/layer bounds

       

      This post from seguso2 is supposed to export coordinates +width and height, but does not work- i get an Error 8800 at line 44

      Re: Export co-ordinates/layer bounds

       

      Can someone help with adding/fixing the width and height to the script to any of these?

      much appreciated,

      Noe

        • 1. Re: Export layer coordinates, layer width and height?
          JJMack Most Valuable Participant

          Here use my script for layer bounds information it just displays some information as a script message.  Perhaps you could combine my script with the script  you have that creates the text file.  Add the information to the text file that is created. My script also set guide line one the layers bounds and across its center.  You do not need to add the guides  the layer bounds info is just four lines of code.

          Capture.jpg

          // enable double-clicking from Mac Finder or Windows Explorer
          #target photoshop // this command only works in Photoshop CS2 and higher
          
          
          // bring application forward for double-click events
          app.bringToFront();
          
          
          // Save the current preferences
          var startRulerUnits = app.preferences.rulerUnits;
          // Set Photoshop to use pixels 
          app.preferences.rulerUnits = Units.PIXELS;
          
          
          try{
            var LB = activeDocument.activeLayer.bounds;
            var LWidth = (LB[2].value) - (LB[0].value);
            var LHeight = (LB[3].value) - (LB[1].value);
            MarkX((LB[0].value + LWidth/2));
            MarkX(LB[0].value);
            MarkX(LB[2].value);
            MarkY((LB[1].value + LHeight/2));
            MarkY(LB[1].value)
            MarkY(LB[3].value)
            alert("'" + activeDocument.activeLayer.name + "' Layer Bounds\nTop Left " +  LB[0].value + "X," +  LB[1].value + "Y   Bottom Right "  +  LB[2].value + "X," +  LB[3].value
            + "Y\nWidth " +  LWidth + "px   Height " + LHeight +"px" 
            + "\nLayer center relative to canvas " + (LB[0].value + LWidth/2) + "X," +  (LB[1].value + LHeight/2) +"Y" 
            );
          }
          catch(e){alert("Requires a layer targered");}
          
          
          // Return the app preferences
          app.preferences.rulerUnits = startRulerUnits;
          function MarkX(x) {
          // =======================================================
          var idMk = charIDToTypeID( "Mk  " );
              var desc61 = new ActionDescriptor();
              var idNw = charIDToTypeID( "Nw  " );
                  var desc62 = new ActionDescriptor();
                  var idPstn = charIDToTypeID( "Pstn" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc62.putUnitDouble( idPstn, idPxl, x);
                  var idOrnt = charIDToTypeID( "Ornt" );
                  var idOrnt = charIDToTypeID( "Ornt" );
                  var idVrtc = charIDToTypeID( "Vrtc" );
                  desc62.putEnumerated( idOrnt, idOrnt, idVrtc );
              var idGd = charIDToTypeID( "Gd  " );
              desc61.putObject( idNw, idGd, desc62 );
          executeAction( idMk, desc61, DialogModes.NO );
          }
          function MarkY(y) {
          // =======================================================
          var idMk = charIDToTypeID( "Mk  " );
              var desc63 = new ActionDescriptor();
              var idNw = charIDToTypeID( "Nw  " );
                  var desc64 = new ActionDescriptor();
                  var idPstn = charIDToTypeID( "Pstn" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc64.putUnitDouble( idPstn, idPxl, y );
                  var idOrnt = charIDToTypeID( "Ornt" );
                  var idOrnt = charIDToTypeID( "Ornt" );
                  var idHrzn = charIDToTypeID( "Hrzn" );
                  desc64.putEnumerated( idOrnt, idOrnt, idHrzn );
              var idGd = charIDToTypeID( "Gd  " );
              desc63.putObject( idNw, idGd, desc64 );
          executeAction( idMk, desc63, DialogModes.NO );
          }
          

           

          The four needed line of code:

           

          var LB = activeDocument.activeLayer.bounds;

          var LWidth = (LB[2].value) - (LB[0].value);

          var LHeight = (LB[3].value) - (LB[1].value);

          alert("'" + activeDocument.activeLayer.name

            + "' Layer Bounds\nTop Left " +  LB[0].value + "X," +  LB[1].value + "Y   Bottom Right "  +  LB[2].value + "X," +  LB[3].value 

            + "Y\nWidth " +  LWidth + "px   Height " + LHeight +"px"  

            + "\nLayer center relative to canvas " + (LB[0].value + LWidth/2) + "X," +  (LB[1].value + LHeight/2) +"Y" ); 

          • 2. Re: Export layer coordinates, layer width and height?
            nvega Level 1

            Thank you JJMack. The script works well as standalone, however I'm unable to combine your script with Paul's so that the result is a text file with the layer name, x, y, w, h.

            • 3. Re: Export layer coordinates, layer width and height?
              JJMack Most Valuable Participant

              I would think all you would need to do is use the four statement  but change the alert message into a write message into the text file.