Skip to main content
dublove
Legend
July 27, 2025
Answered

How can I find the leftmost image in sel[j].geometricBounds?

  • July 27, 2025
  • 1 reply
  • 149 views

When selecting multiple images, the leftmost image may not necessarily be the first in the array.
It could be the topmost image.

I guess that sel[j].geometricBounds[1] has the smallest value, which is the leftmost image visually. I want to use it as a reference and get its geometricBounds[1] value.

I now need to find the leftmost image among three images. How should I write the code?

 

Thnaks.

 

var sel = app.documents[0].selection;
for(i=0;i<sel.length;i++){ .

. . . . .
var leftmost = (sel[i].geometricBounds)[1];
}

 

Correct answer rob day

You can check the left bounds against the left bounds of first object in the selection like this

 

var sel = app.documents[0].selection;

//get the left bounds of the first object in the selection
var lm = sel[0].geometricBounds[1]

//check the left bounds of the other objects
for (var i = 1; i < sel.length; i++){
    if (sel[i].geometricBounds[1] < lm) {
        lm = sel[i].geometricBounds[1]
    } 
};   
alert("Left side of the selection: " + lm)

 

 

 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
July 27, 2025

You can check the left bounds against the left bounds of first object in the selection like this

 

var sel = app.documents[0].selection;

//get the left bounds of the first object in the selection
var lm = sel[0].geometricBounds[1]

//check the left bounds of the other objects
for (var i = 1; i < sel.length; i++){
    if (sel[i].geometricBounds[1] < lm) {
        lm = sel[i].geometricBounds[1]
    } 
};   
alert("Left side of the selection: " + lm)

 

 

 

dublove
dubloveAuthor
Legend
July 27, 2025

Thank you very much!
May be. . . . .. .  it is not necessary.

 

It's not easy.
Today,

var sb=sel[j].geometricBounds;

 

The sb[2] was written as ih, it should be (sb[0]+ih).
I missed writing sb[0] and was depressed all day.