How can I get the height of a story in InDesign?

Hello,

I m building a production robot that takes Xtags formated text and creates an ad preview using either Quark or InDesign. The templates I am using support multiple columns. The idea is that the ad copy might span more than one column. I need to retrieve the total size of the flowed text.

I have an AppleScript that flows Xtags into Quark, then another AS that determines the height of the text and outputs the size to a new text file. This was very simple is Quark with the following code:

tell application “QuarkXpress”
activate
tell document 1
set myVar to height of the text in story 1 as string – This is the line that determines the height
end tell
set myfile to (open for access file “tempfilepath” with write permission)
set eof myfile to 0
write myVar to myfile
close access myfile
end tell

The returned value is in points which works great for my needs.

I am now trying to to do the same thing with InDesign. I can’t find anything in the InDesign library nor on the web that will return the height of the story. I have been looking for 2 days, I need some help please.

Thanks,
Jeff

InDesign does not have a height and width property like Quark does, you need to calculate it using the geometric bounds of the object. The story in InDesign is does not have geometric bounds and can span multiple text frames, I think that Quark is similar in this regard but it has been a while since I have scripted it.

Now to get the height of the object you can use the text frame’s geometric bounds:

tell application "Adobe InDesign CS3"
	set theBounds to geometric bounds of text frame 1 of document 1
	set theHeight to (item 3 of theBounds) - (item 1 of theBounds)
	set theWidth to (item 4 of theBounds) - (item 2 of theBounds)	
end tell

As long as what you need is the height of the text frame. If you need the height of the text inside the frame then you will need to deal with the text which does not have a geometric bounds property. To do this reliably without worrying about any other measures or finding the last line in the column(s) you can use the baseline properties of the text. Subtract the Ascent from the first baseline, add the descent to the last baseline then subtract the first value from the last. The code for that would look something like this:

tell application "Adobe InDesign CS3"
	tell text of text frame 1 of document 1
		set H1 to baseline
		set H2 to ascent
		set H3 to end baseline
		set H4 to descent
		set theHeight to ((H3 + H4) - (H1 - H2))
		set W1 to horizontal offset
		set W2 to end horizontal offset
		set theWidth to (W2 - W1)
	end tell
end tell

Hi Jerome,

Thank you for the reply. It seems to me this should be easier that is turns out it is.

The second scriplet doesn’t return a value. Each variable is NULL.

The first scriplet works a bit in the direction that I need. To make it work for me I need to shrink the text frame to fit the content. This is another thing that I have been beating my head on. It turns out that you can’t shrink-to-fit a text frame that is formated with more than one column.

So I have a document formatted with 6 columns. When I place a text frame on the document for my text flow, it doesn’t use the document columns. I then format the text frame to 6 column and the option for shrink-to-fit becomes unavailable.

I tried creating a single text frame for each column and link them for auto-flow. The shrink-to-fit also is unavailable with linked text frames.

Is there a way to have a text frame format using the document formats without specifying the the number of columns?

Thanks,
Jeff

Hello,

I discovered a method to address my needs. In review, I need to measure the height of text that is flowed into a document. The content might span multiple columns.

We decided to create a document that is 1296 picas tall (648 ft.). Make the template X columns (based on the requirements). Then make one text frame in the first column that is the height of the document.

My AppleScript flows the text.
Selects the text frame.
Then perform a ‘fit-frame-to-content’

I had a problem getting the ‘fit’ command. There is no AppleScript command to do this, I used GUI scripting to make it work. This wasn’t that easy. Then normal menu reference type of script didn’t work and didn’t return an error.

I ended up using a keystroke call to make the process happen. This is the final script:


tell application "Adobe InDesign CS4"
	activate
	open "Boot:Users:admin:Desktop:template.indd"
	save document 1 to "Boot:Users:admin:Desktop:fooBar.indd"
	tell document 1
		tell parent story of text frame 1
			get text with Xtags from "Boot:Users:admin:Desktop:fooBar.xtg" --with quote conversion
		end tell
		select text frame 1
		tell application "System Events"
			tell the application process "Adobe InDesign CS4"
				keystroke "c" using {command down, option down}
			end tell
		end tell
	end tell
	save document 1
	-- The follow returns the height of the text frame.
	set theBounds to geometric bounds of text frame 1 of document 1
	set theHeight to (item 3 of theBounds) - (item 1 of theBounds)
	set theWidth to (item 4 of theBounds) - (item 2 of theBounds)
	return theHeight
end tell

Thanks for the help.
Jeff