Skip to main content
dublove
Legend
Jul 27, 2025 11:13 AM UTC
Answered

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

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];
}

 

rob day
rob dayCorrect answer
Community Expert
Jul 27, 2025 2:25 PM UTC

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)

 

 

 

2 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Jul 27, 2025 2:25 PM UTC

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)

 

 

 

Translate
dublove
dubloveAuthor
Legend
Jul 27, 2025 4:52 PM UTC

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.

Translate