• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export layer coordinates, layer width and height?

New Here ,
Jun 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

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.

Export coordinates

 

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

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

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

TOPICS
SDK

Views

3.4K

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 Expert ,
Jun 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

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

JJMack

Votes

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 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

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.

Votes

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
Community Expert ,
Jun 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

LATEST

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.

JJMack

Votes

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