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
Hi childsmile,
See also:
http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap
@+
Marc
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.
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
Copy link to clipboard
Copied
Rather than storing the rotation angle and restoring it, you can also just use undo.
Copy link to clipboard
Copied
There is a typo in my last line of code. It should read:
app.selection[0].rotationAngle=rA;
Uwe
Copy link to clipboard
Copied
Hi childsmile,
See also:
http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap
@+
Marc
Copy link to clipboard
Copied
Thanks Marc,It is very helpful to me
Copy link to clipboard
Copied
Hello, Marc!
Wow. That was the solution I was hoping for. Great tutorial.
Thank you very much!
Uwe