Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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")
}
Copy link to clipboard
Copied
Thanks. I'm pretty sure tried that but kept getting 'undefined' empty sets.
What did work was s[1].as('px') ];
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I also think some versions of Photoshop scripting selection bouns was either not posible or had a bug in it.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now