Skip to main content
Participant
November 1, 2011
Answered

selection.bounds operation?

  • November 1, 2011
  • 3 replies
  • 6201 views

I have this simple jsx script where I want to get the bounds of a selection:

try

    {

        var s = app.activeDocument.selection.bounds

        alert(s.toSource())

    }

catch(e)

    {

        alert("No selection")

    }

It does detect that there is a selection present but does not return that array of x,y coordinates that bounds the selecton.

The alert displays [({}),({}),({}),({})]

all elements of the array are determined to be undefined.

Any help is appreciated.

Thanks!

Ray

This topic has been closed for replies.
Correct answer raybeau528

I found the solution to the problem in this forum using this:

var selectionXY = [ app.activeDocument.selection.bounds[0].as('px'), app.activeDocument.selection.bounds[1].as('px') ];

Thanks to whoever provided the answer there!

Ray

3 replies

JJMack
Community Expert
Community Expert
November 1, 2011

I also think some versions of Photoshop  scripting selection bouns was either not posible or had a bug in it.

JJMack
Inspiring
November 1, 2011

I also think some versions of Photoshop  scripting selection bouns was either not posible or had a bug in it.

This is true. When the bounds property was first introduced (CS2) it didn't work. CS3+ should be fine.

Inspiring
November 1, 2011

try

    {

        var s = app.activeDocument.selection.bounds

        alert(s[0]+","+s[1]+","+s[2]+","+s[3]) // 0 and 1 are x and y for top left corner and 2 and 3 are x and y for bottom right corner.

    }

catch(e)

    {

        alert("No selection")

    }

Participant
October 17, 2014

I'm looking for some functionality like this a little bit more complicated

1. Find rulers zero point or top left corner of document
2. Show dialog and ask user for coordinates - lets say in pixels.
3. Move current, active layer to user coordinates, bur RELATIVE TO zero point or to top left corner of document.

I'm not developer so I need support from people like You.
Hope some one can and will help me, please.

Thank You in advice. Regards.

raybeau528AuthorCorrect answer
Participant
November 1, 2011

I found the solution to the problem in this forum using this:

var selectionXY = [ app.activeDocument.selection.bounds[0].as('px'), app.activeDocument.selection.bounds[1].as('px') ];

Thanks to whoever provided the answer there!

Ray