InDesign Image Box Size Help

Hi Guys,
I am using the below script to place MathType Equations into an InDesign File
Basically it searches for tags <<Filename.eps>> and replaces it with a inline graphic.

My question is:
Is there anyway I can get it to read the height of the InLine Graphic Box and then get it to baseline shift it down half of the height of it, instead of the set amount of -10pt that is uses now?

tell application "Adobe InDesign CS3"
	tell document 1
		set baselineVar to "Yes"
		set countVar to 0
		set imageCount to 0
		set docPath to file path as alias
		tell application "Finder"
			set imageFolder to folder (choose folder with prompt "Please choose the folder containing the appropriate MathType files") --"MathType" of artFolder
		end tell
		activate
		set allStories to stories
		repeat with s from 1 to count of items of allStories
			set theStory to item s of allStories
			if class of theStory is story then
				set theLim to count of words of theStory
				try
					repeat with i from 1 to theLim
						if word i of theStory contains "<<" then
							set theText to contents of word i of theStory as Unicode text
							set theOffset to (offset of "<<" in theText)
							set endOffset to (offset of ">>" in theText)
							set imageName to characters (theOffset + 2) through (endOffset - 1) of theText as string
							set imageFolderPath to ((imageFolder as string) & imageName)
							set wholeTag to characters theOffset through (endOffset + 1) of theText as string
							if baselineVar = "Yes" then
								set baseline shift of characters theOffset through (endOffset + 1) of word i of theStory to -10
							end if
							delete characters theOffset through (endOffset) of word i of theStory
							tell theStory
								tell word i
									tell character theOffset
										place imageFolderPath as alias
										set countVar to (countVar + 1)
									end tell
								end tell
							end tell
						end if
					end repeat
				end try
			end if
		end repeat
	end tell
	activate
	if countVar = 0 then
		display dialog "No Images were found" buttons "OK" default button 1 with icon 2
	else if countVar = 1 then
		display dialog "1 lonely Images has been placed." buttons "OK" default button 1
	else
		display dialog (countVar as string) & " Images have been placed." buttons "OK" default button 1
	end if
end tell

Thanks
Marcus

Model: G5
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

This should give you the idea of how to work it into your script:

set theImage to choose file

tell application "Adobe InDesign CS3"
	tell document 1
		set theSelection to selection --this returns a list of object references
		tell item 1 of theSelection to set theInlineGraphic to place theImage
		set theBounds to geometric bounds of parent of item 1 of theInlineGraphic
		set baseline shift of parent of parent of item 1 of theInlineGraphic to -(((item 3 of theBounds) - (item 1 of theBounds)) / 2)
	end tell
end tell

Another option would be to set the anchor offset instead of the baseline shift:

set theImage to choose file

tell application "Adobe InDesign CS3"
	tell document 1
		set theSelection to selection --this returns a list of object references
		tell item 1 of theSelection to set theInlineGraphic to place theImage
		set theBounds to geometric bounds of parent of item 1 of theInlineGraphic
		set anchor yoffset of anchored object settings of parent of item 1 of theInlineGraphic to -(((item 3 of theBounds) - (item 1 of theBounds)) / 2)
	end tell
end tell

For everyone who looked at this, here is Marcus’s script revised a bit and commented:

set baselineVar to "Yes"
set NotPlacedLog to {}

tell application "Finder" to set imageFolder to folder (choose folder with prompt "Please choose the folder containing the appropriate MathType files") as string

tell application "Adobe InDesign CS3"
	activate
	try
		(* get's a list of every word in every story that starts with << and ends in >> 
		    and steps through that list. This eliminates the need to check word by word *)
		tell document 1 to set theWords to object reference of every word of every story whose contents begins with "<<" and contents ends with ">>"
	on error
		--captures the error if there are no words that start with << and end with >>
	end try
	(* Repeats through the list backward to eleminate error's in the
	   indexing as it replaces the "words" with the placed graphic *)
	repeat with i from (count of theWords) to 1 by -1
		set imageName to (characters 3 through -3 of item 1 of theWords) as string
		if exists (alias imageName) then
			tell item i of theWords to set theInlineGraphic to place alias (imageFolder & imageName)
			set theBounds to geometric bounds of parent of item 1 of theInlineGraphic
			set anchor yoffset of anchored object settings of parent of item 1 of theInlineGraphic to -(((item 3 of theBounds) - (item 1 of theBounds)) / 2)
		else
			--log for files that do not exist
			copy item i of theWords to end of NotPlacedLog
		end if
	end repeat
	display dialog ((count of theWords) as string) & " Images have been placed." buttons "OK" default button 1
end tell

Note I am using anchor offset instead of baseline shift, either could be used. I chose anchor offset because when you place an inline graphic in a paragraph with auto leading the line of text can get pushed down the height of the graphic. Baseline shift does leaves the height based off the graphic where anchor offset reduces it the amount of the offset.

Sorry, I got this error message.


When I deleted the “alias” from the Place line, it works, but it inserts the first images over and over for each instance it find << >>

Thanks
Marcus

you don’t use the index variable i properly.
Change this line


 set imageName to (characters 3 through -3 of item 1 of theWords) as string

into


 set imageName to text 3 through -3 of item i of theWords

Thanks Stefan,

I originally was moving through using:

repeat with aWord in theWords

but ran into problems with the references so changed it to iterate backward through the list but forgot to add in the item i to the code when I changed it.

Jerome

Thanks so much Jerome.
This is working fantastically …

The only change I made was StefanK’s line, except I kept yours and changed the 1 to be i
Now that it works I can get this god awful job done and then go back Line for line and work out what does what.

Thanks again

Marcus

set baselineVar to "Yes"
set NotPlacedLog to {}

tell application "Finder" to set imageFolder to folder (choose folder with prompt "Please choose the folder containing the appropriate MathType files") as string

tell application "Adobe InDesign CS3"
	activate
	try
		tell document 1 to set theWords to object reference of every word of every story whose contents begins with "<<" and contents ends with ">>"
	on error
		--captures the error if there are no words that start with << and end with >>
	end try
	tell document 1
		repeat with i from (count of theWords) to 1 by -1
			set imageName to (characters 3 through -3 of item i of theWords) as string
			if exists (alias imageName) then
				tell item i of theWords to set theInlineGraphic to place (imageFolder & imageName)
				set theBounds to geometric bounds of parent of item 1 of theInlineGraphic
				set anchor yoffset of anchored object settings of parent of item 1 of theInlineGraphic to -(((item 3 of theBounds) - (item 1 of theBounds)) / 2)
			else
				--log for files that do not exist
				copy item i of theWords to end of NotPlacedLog
			end if
		end repeat
	end tell
	display dialog ((count of theWords) as string) & " Images have been placed." buttons "OK" default button 1
end tell

Both lines


 set imageName to (characters 3 through -3 of item i of theWords) as string

and


 set imageName to text 3 through -3 of item i of theWords

have the same result, but the second version saves one coercion, because it’s included in the text command