10 Replies Latest reply on Apr 15, 2013 2:02 PM by StephanPeterson

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

    StephanPeterson

      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

        • 2. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
          StephanPeterson Level 1

          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.

          • 4. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
            Michael L Hale Level 5

            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

            • 5. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
              StephanPeterson Level 1

              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.

               

              Screen Shot 2013-04-15 at 1.31.35 PM.png

              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

              • 6. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
                Muppet Mark Level 5

                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…

                 

                Screen shot 2013-04-15 at 20.46.24.png

                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

                • 7. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
                  StephanPeterson Level 1

                  Mark, thanks for helping me with this. Very curious that it's working for you. While I'm puzzled, it's good to know that it's possible. Now to figure out why it's not working for me. I'm on Mac OS X 10.8.3 and have tried with CS4-6. What version fo the Mac OS are you on? Any understanding about why it's working for you and not me is GREATLY appreciated.

                   

                  Thanks!

                  Stephan

                  • 8. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
                    StephanPeterson Level 1

                    I don't know why I didn't see this earlier, but it appears that it works if the image's resolution is 72 dpi. My images are 300 dpi and need to be so. Looks like I'll have to figure out a way to make it work with 300 dpi images.

                     

                    Stephan

                    • 9. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
                      Muppet Mark Level 5

                      Stephan… I used to use AppleScript in the days of CS2 but I now prefer using Adobe's ExtendScript… I now use CS5 jumped past the two versions between… I tested the code using CS5 on SnowLeopard… You will find that there a numerous occasions where photoshop will presume 72dpi ( which my document was ). I've always found it better to change a documents resolution to 72dpi as part of the script then put it back when done… Doing this should resolve your issues…

                      • 10. Re: Can't get "true" height of text box (text object) in Photoshop CS4-CS6 on Mac
                        StephanPeterson Level 1

                        Nothing like answering your own questions!

                         

                        Looks like I you need to make sure you're settings the unit type for rulers and type both to pixels and then also divide the documents resoution by 72. Here's my updated code:

                         

                        tell application "Adobe Photoshop CS4"

                        --Capture unit types

                                  set initialTypeUnit to type units of settings

                                  set initialRulerUnit to ruler units of settings

                        --Set unit types to pixels

                                  set ruler units of settings to pixel units

                                  set type units of settings to pixel units

                        activate

                                  tell current document

                                            set docRes to resolution

                                            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) * (docRes / 72)

                                            set textObjectHeight to (height of text object of art layer 1) * (docRes / 72)

                          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

                        --Reset unit types

                                  set ruler units of settings to initialRulerUnit

                                  set type units of settings to initialTypeUnit

                        end tell