Skip to main content
Known Participant
April 11, 2013
Question

Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac

  • April 11, 2013
  • 2 replies
  • 2086 views

I'm seeing this behavior in CS4, CS5 and CS6 on the Mac using AppleScript. When I get the height of a text object layer as such:

     tell app "Adobe Photoshop CS4"

          tell current document

               set textObjectHeight to height of text object of art layer 1

          end tell

     end tell

The value returned doesn't match the height of the text object. In my mind the text object is the box that's displayed when I click on text in a text layer with the text tool active. The value for the width appears to match, just as I'd expect.

I'm trying to get the height and width of the text box (text object) so that I can draw a box "underneath" it on another layer so that one can tell where the text box is. Kind of an FPO-type assistant. I'm currently using the position values and the height and width to create a colored box. I realized that the height isn't exactly right.

Any help would be great appreciated. I've not explored the use of Javascript thus far, but am open to that as a solution.

Thanks,

Stephan

This topic has been closed for replies.

2 replies

Inspiring
April 13, 2013

Has your text been transformed/scaled? CS6 reports a different value with transformed text than earlier versions. If so this thread may help but it's in javascript. http://forums.adobe.com/thread/1160449?tstart=90

Known Participant
April 15, 2013

No, the text isn't transformed, but I'm not trying to get the height of the text itself. I'm trying to get the height of the text box itself. I've attached a screenshot.

I've included a screenshot that shows the box that was drawn under the text object based on the position, height and width values. As you can see, the box isn't extending as far as it should. Here's that code:

tell application "Adobe Photoshop CS4"

     activate

     tell current document

          set textObjectPosition to position of text object of art layer 1

          set textObjectPositionX to item 1 of textObjectPosition

          set textObjectPositionY to item 2 of textObjectPosition

          set textObjectWidth to width of text object of art layer 1

          set textObjectHeight to height of text object of art layer 1

          make art layer at end with properties {name:"fill"}

          select region {{textObjectPositionX, textObjectPositionY}, {textObjectPositionX + textObjectWidth, textObjectPositionY}, {textObjectPositionX + textObjectWidth, textObjectPositionY + textObjectHeight}, {textObjectPositionX, textObjectPositionY + textObjectHeight}} without antialiasing

          fill selection with contents {class:RGB color, red:255, green:0, blue:0} blend mode normal opacity 100 without preserving transparency

          deselect

     end tell

end tell

The height should be approximately 200 pixels but is reporting at 168ish. The width is obviously fine.

Stephan

Inspiring
April 15, 2013

I tried your code and it works just fine here… I used CS5 to try it… Here is a screen shot… I just put a solid fill layer at the bottom so you can see the guides…

Script editor's event log gives me…

tell application "Adobe Photoshop CS5"

  activate

  get position of text object of art layer 1 of current document

                    {150.0, 100.0}

  get width of text object of art layer 1 of current document

                    800.0

  get height of text object of art layer 1 of current document

                    449.999969482422

  make at end of current document with properties {name:"fill"} new art layer

                    art layer 2 of document "Untitled-1"

          select current document region {{150.0, 100.0}, {950.0, 100.0}, {950.0, 549.999969482422}, {150.0, 549.999969482422}} without antialiasing

  current application

  fill selection of current document with contents {class:RGB color, red:255, green:0, blue:0} blend mode normal opacity 100 without preserving transparency

  current application

  deselect current document

  current application

end tell

pixxxelschubser
Community Expert
Community Expert
April 12, 2013

Try the Script at the end of this thread:

http://forums.adobe.com/thread/1171121?tstart=0

Known Participant
April 12, 2013

Maybe it's my lack of JS understanding, but I'm not grasping what you were directing me to in that script. Sorry for my denseness.

pixxxelschubser
Community Expert
Community Expert
April 12, 2013

Have you tried it?