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

How to get text frame width, height

New Here ,
Dec 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

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

Views

1.1K

Translate

Translate

Report

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

Votes

Translate

Translate
Engaged ,
Dec 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

app.selection[0].rotationAngle=rA;

Uwe

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi childsmile,

See also:

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

@+

Marc

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks Marc,It is very helpful to me

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Hello, Marc!

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

Thank you very much!

Uwe

Votes

Translate

Translate

Report

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