Skip to main content
This topic has been closed for replies.
Correct answer Stephen Marsh

You need to get the bounding info and calculate the width and height values from the bounds.

 

//    Bounds:
//    + - - - - - - - [1] - - - - - - - +
//    |                                 |
//    |                                 |
//   [0]                               [2]
//    |                                 |
//    |                                 |
//    + - - - - - - - [3] - - - - - - - +

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

alert(
'Layer Bounds -' + '\r' +
'X1 - [0]: ' + app.activeDocument.activeLayer.bounds[0] + '\r' +
'Y1 - [1]: ' + app.activeDocument.activeLayer.bounds[1] + '\r' + 
'X2 - [2]: ' + app.activeDocument.activeLayer.bounds[2] + '\r' +
'Y2 - [3]: ' + app.activeDocument.activeLayer.bounds[3] + '\r' + 
'Width: ' + (app.activeDocument.activeLayer.bounds[2].value - app.activeDocument.activeLayer.bounds[0].value) + ' px\r' +
'Height: ' + (app.activeDocument.activeLayer.bounds[3].value - app.activeDocument.activeLayer.bounds[1].value) + ' px'
);

app.preferences.rulerUnits = savedRuler;

 

2 replies

Kukurykus
Legend
March 28, 2022
with(activeDocument.activeLayer) bounds[2] - bounds[0]
Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
March 28, 2022

You need to get the bounding info and calculate the width and height values from the bounds.

 

//    Bounds:
//    + - - - - - - - [1] - - - - - - - +
//    |                                 |
//    |                                 |
//   [0]                               [2]
//    |                                 |
//    |                                 |
//    + - - - - - - - [3] - - - - - - - +

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

alert(
'Layer Bounds -' + '\r' +
'X1 - [0]: ' + app.activeDocument.activeLayer.bounds[0] + '\r' +
'Y1 - [1]: ' + app.activeDocument.activeLayer.bounds[1] + '\r' + 
'X2 - [2]: ' + app.activeDocument.activeLayer.bounds[2] + '\r' +
'Y2 - [3]: ' + app.activeDocument.activeLayer.bounds[3] + '\r' + 
'Width: ' + (app.activeDocument.activeLayer.bounds[2].value - app.activeDocument.activeLayer.bounds[0].value) + ' px\r' +
'Height: ' + (app.activeDocument.activeLayer.bounds[3].value - app.activeDocument.activeLayer.bounds[1].value) + ' px'
);

app.preferences.rulerUnits = savedRuler;

 

fraktallAuthor
Known Participant
March 28, 2022

Thanks! This should do