Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for professional graphic designers and non-designers trying to do their own graphic design. It's 100% free, no registration required.

Is there any way to get the x/y position of the origin of a paragraph text box via Javascript, excluding use of the Photoshop UI?

This image shows my predicament; what I need vs what the Photoshop Javascript is giving me: enter image description here

The .bounds property gives the coordinates of the actual text content, as shown in the image by the guides and the green circles. I got this by running the simple script alert(app.activeDocument.activeLayer.bounds);, which gave these measurements:enter image description here

What I would expect to be stored in .bounds, and what I need, is the top-left and bottom-right coordinates of the paragraph box. Does anybody have any good way of getting this?

TextItem.width and TextItem.height are getting close, but they give no indication of where on the canvas the text item actually is.

Right now I'm having to find the center of the bounds coordinates and extrapolate from there, but that is not precise enough because it varies 1 or 2 pixels depending on the characters in the text field.

share|improve this question
add comment

1 Answer

What you'll want to use is: textItem.position, that will return the coordinates of the top-left most point of the bounding box you're looking for.

Example code of textItem.position:

alert(app.activeDocument.activeLayer.textItem.position);

Then if you want the bottom-right point, simple add the height and width of the box to that coordinate.

Something like this:

var right = textItem.position[0] + textItem.width;
var bottom = textItem.position[1] + textItem.height;

position[0] will return the x coordinate and position[1] will return the y coordinate.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.