Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

selection.bounds operation?

Community Beginner ,
Oct 31, 2011 Oct 31, 2011

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

TOPICS
Actions and scripting
6.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Oct 31, 2011 Oct 31, 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

Translate
Adobe
Community Beginner ,
Oct 31, 2011 Oct 31, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 31, 2011 Oct 31, 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")

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2011 Nov 01, 2011

Thanks. I'm pretty sure  tried that but kept getting 'undefined' empty sets.

What did work was s[1].as('px') ];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 01, 2011 Nov 01, 2011

It depends on what your settings are. The .as('px') will always display the coordinates in pixels. If you are set to display rulers and type in pixels by default, that shouldn't be needed. Best to keep it just in case, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 01, 2011 Nov 01, 2011

jugenjury wrote:

The .as('px') will always display the coordinates in pixels.

That should be true, but it's not. If the ruler is set to percent .as('px') returns NaN. Which seems to me defeats the whole point of UnitValues. But I guess this is low on the Abode bug list. So it is a good idea to set the ruler even if you are using UnitValues and their methods.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2014 Oct 17, 2014
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2011 Oct 31, 2011

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

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 31, 2011 Oct 31, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines