Illustrator -- getting height of text in a text frame

Is there any way to determine the height of the text within an Illustrator text frame using Applescript?

I have a bunch of text frames that have varying amounts of text (some have a few lines, others have a lot) using different font sizes. I’d love to be able to tell where the “bottom” of each text frame is so that I can insert a graphic right underneath it.

I could probably build a script that would count the number of lines, multiply by the font sizes, add the leading, etc., but I hoped there would be an easier way.

Another way of doing the same thing would be to move up the bottom of the text box until the text overflows, but I don’t know of a way to do that either.

Thanks.

John:

Here is a quickie.

tell application "Adobe Illustrator"
	(height of text frame 1 of current document) / 72 -- Converted to inches
end tell

Note: This is the measure of the bounding box of the text frame, not necessarily the actual height of the characters. For example, the word “one” is smaller than the bounding box since there’s no descenders, ascenders, or capitals. For general use the bounding box should suffice though.

Have fun!
Jim Neumann
BLUEFROG

Thanks for the help, but unfortunately I need to be pretty precise on the total height of the text within the text frame, descenders included. Some of these text frames have large chunks of open space between the bottom of the bottom-most line and the bottom of the text frame itself, and I need to eliminate those gaps if I can.

How about duplicating the frame, create outlines, read in base of visible bounds, remove outlined text.

tell application "Adobe Illustrator"
	set Doc_Ref to current document
	tell Doc_Ref
		set Text_Frame to duplicate text frame 1 to beginning
		set Text_Outlines to convert to paths Text_Frame
		set Text_Base to item 4 of visible bounds of Text_Outlines
		delete Text_Outlines
	end tell
end tell
Text_Base

John:

You’re not going to be able to get these measurements from live text since the height of characters is not an accessible property. Here’s another quickie that converts the text to outlines, measures the results, then deletes the copy. Note that you’ll have to uncomment the delete line. I left it commented out so you can verify the results.)


tell application "Adobe Illustrator"
	tell document 1
		set convertedText to (convert to paths (duplicate text frame 1 to before text frame 1))
		set textHeight to (height of convertedText) / 72
		-- Uncomment this next line so the copy is cleaned up in production. I've commented it so you can verify the measurements in testing.
		-- delete convertedText
	end tell
end tell
textHeight -- This is just for reporting the value in Script Editor. Get rid of it / comment it when you're done.

Jim

Note: Per Mark’s example you can request visible bounds as well. (You asked for Height so that’s what I gave you.)
Visible Bounds: is a list {TopLeftX, TopLeft, Y, BottomRight,X, BottomRightY}
Position: the top left point of the bounding box of an object {TopLeftX, TopLeftY}

Bluefrog, Mark67, that looks like a good solution. Thanks much.