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

How to get text frame width, height

New Here ,
Dec 12, 2009 Dec 12, 2009

hi,

I am unable to find the text frame width and height using JS.

Can any tell how to find the values.

Thanks

Mohanraj

TOPICS
Scripting
1.5K
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

Guide , Dec 13, 2009 Dec 13, 2009

Hi childsmile,

See also:

http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap

@+

Marc

Translate
Engaged ,
Dec 12, 2009 Dec 12, 2009

Hi Mohenraj,

Use textFrame.geomentricBound properties, which give the four co-ordinates value like top, left, bottom, right.

height = top-bottom

width = left-right.

Hope this will helps you.

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
Community Expert ,
Dec 13, 2009 Dec 13, 2009

You can use the visibleBounds in case the text frame got a stroke width and you want to know the overall width and height. It's all in the Object Model Viewer of the ESTK.

But let me asume the text frame is rotated. Now your formula:

height = top-bottom

width = left-right

is not true any more. In that case you could rotate it back to zero (rotationAngle=0) and do the measurements then…
But don't forget to rotate it back to its original position:

//Store the actual rotation angle of the selected object to a variable:
var rA=app.selection[0].rotationAngle;

//Set the objects rotation angle back to zero:
app.selection[0].rotationAngle=0;
//Now the object is prepared for measuring.

//Then store the visual bounds to a variable:
var gB=app.selection[0].visibleBounds;
//visibleBounds is an Array of four entries (gB[0] to gB[3])
//in the format [y1, x1, y2, x2] of the current coordinate system.

//You get its width by substracting x1 from x2:
var oW=gB[3]-gB[1];
//And its height by substracting y1 from y2:
var oH=gB[2]-gB[0];

//Then restore the objects rotation angle:
app.selection[0].rotationAngle=a;

Uwe

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
Advocate ,
Dec 13, 2009 Dec 13, 2009

Rather than storing the rotation angle and restoring it, you can also just use undo.

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
Community Expert ,
Dec 13, 2009 Dec 13, 2009

There is a typo in my last line of code. It should read:

app.selection[0].rotationAngle=rA;

Uwe

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
Guide ,
Dec 13, 2009 Dec 13, 2009

Hi childsmile,

See also:

http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap

@+

Marc

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 ,
Dec 13, 2009 Dec 13, 2009

Thanks Marc,It is very helpful to me

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
Community Expert ,
Dec 13, 2009 Dec 13, 2009
LATEST

Hello, Marc!

Wow. That was the solution I was hoping for. Great tutorial.

Thank you very much!

Uwe

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