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

Text box width

New Here ,
Sep 06, 2013 Sep 06, 2013

Hi,

I'm wanting to find the width of a text box and if it's longer than say 200 pixels, decrement the font size (points) by one until the text box width is less than 200 pixels. I'm guessing I'm going to need some form of loop here but I'm having problems with this.

I've not included all of my code just the important parts.

TextItem.Size = 50

TextItem.Kind = 2 (to allow me to find the width)

Dim TextWidth = TextItem.Width

Now my thoughts for the loop are...

While TextWidth > 200

TextItem.Size -= 1

TextWidth = TextItem.Width

End While

I'm not the best programmer so don't know if that loop is completely correct but my idea behind it is that while the text box width is greater than 200, decrease the font size by one, find the new text box width then if this is still greater than 200, repeat the process until it's less.

The part i seem to be having a problem with is the "TextWidth = TextItem.Width" inside the while loop. From testing I know that when the text box width is greater than 200 pixels, it correctly enters the loop, decreases the font size, BUT I can't seem to get it to find the new width of the text box. Instead it appears to be still using the original value for width and hence never ending the loop.

Can somebody please point me in the direction of where I'm going wrong?

Thanks in advance.

TOPICS
Actions and scripting
1.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

Guru , Sep 06, 2013 Sep 06, 2013

That code looks like VBS( or some other VB flavor ). If VBS works the same way javascript does, changing the text size will not change the text box width.

There are two types of text layers, point text and paragraph text. The width property only applies to paragraph text but is the width of the text bounding box, not the width of the text itself.

You should be able to get the width of the text from the text layer's bounds property.

Translate
Adobe
Guru ,
Sep 06, 2013 Sep 06, 2013

That code looks like VBS( or some other VB flavor ). If VBS works the same way javascript does, changing the text size will not change the text box width.

There are two types of text layers, point text and paragraph text. The width property only applies to paragraph text but is the width of the text bounding box, not the width of the text itself.

You should be able to get the width of the text from the text layer's bounds property.

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 ,
Sep 07, 2013 Sep 07, 2013

Thanks for the reply Michael.

I just assumed that changing the font size would change the size of the text box. That's obviously why it's not exiting the loop then and hence not working.

I'll have a look into the bounds property like you suggested then, thanks.

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 ,
Sep 07, 2013 Sep 07, 2013

If you don't mind pointing me in the right direction with this bounds property it would be much appreciated. I've tried searching through this forum, the photoshop scripting guides and google but I'm not finding the answer I'm after.

From what I've found it looks to be something like...

Dim TextWidth = ArtLayer.Bounds[2] - ArtLayer.Bounds[0]

The language I'm using is VB.

Thanks in advance.

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 ,
Sep 07, 2013 Sep 07, 2013

Seems I've worked this out now by using the bounds property.

Thanks for your help 🙂

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 ,
Sep 07, 2013 Sep 07, 2013
LATEST

Glad you got it working. I was looking in the VBS guide to see how it's done so I could post an example but I didn't make much progress.

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