Skip to main content
Inspiring
December 5, 2022
Answered

Capture Tallest Shape

  • December 5, 2022
  • 2 replies
  • 965 views

I am able to get the height of the full selection, but I am trying to get the height of the tallest shape in the selection. 

Where does my code snippet need to change?

var maxHeight = 0;
// Capture Letter Height
for (var i = 0; i < doc.selection[i].height; i++) {
    if (doc.selection[i].height > maxHeight) { var maxHeight = doc.selection[i].height; };
  }
  var ltrHeight = maxHeight / 72;

 

Thank you!

This topic has been closed for replies.
Correct answer Charu Rajput

and I randomly get this error...  

 


Hi @BryanPagenkopf 

Assuming, you have expanded the text. Try the following version.

var maxHeight = 0;
var doc = app.activeDocument;
// Capture Letter Height
for (var i = 0; i < app.selection.length; i++) {
    var _item = app.selection[i];
    if (_item.height > maxHeight) {
        var maxHeight = _item.height;
    };
}
var ltrHeight = maxHeight / 72;

 

2 replies

Mylenium
Legend
December 5, 2022

You probably need to add a Math.max() to your i so it only returns the tallest shape in the loop, not the cumulative values.

 

Mylenium

Charu Rajput
Community Expert
Community Expert
December 5, 2022

Hi @BryanPagenkopf 

Could you please post the screen shot from which you want to calculate the height?

Best regards
Inspiring
December 5, 2022

While I would prefer the "T" at .25" I understand that the lower case "l" is slightly taller

 

Inspiring
December 5, 2022

and I randomly get this error...