Indesign: Align placed image to container top

Hi!

I’m trying to get a placed image in InDesign to align to the top of the container frame.
I’ve successfully placed the image and used the fit command to fit the image, but I want it to align to the top of the box, not the center… Any thoughts?

here is the code:

	tell rectangle "EventLogo"
		try
			place "Logo4c.eps"	
		on error
			display dialog "Could not get Logo"
		end try
	end tell

	fit rectangle "EventLogo" given proportionally

I won’t ask why - I’m sure you have your reasons - but you can’t to this through the indesign GUI - but you could acomplish this using geometric bounds…but it will be a little tricky. this code will get you started.

for example:

tell application "Adobe InDesign CS2"
	set myDoc to the active document
	tell myDoc
		--get the geo's of the selected frame (top/left/bottom/right)
		set {tf, lf, bf, rf} to geometric bounds of selection
		
		--get the geo's of the graphic that is placed in the frame
		set {tg, lg, bg, rg} to geometric bounds of graphic 1 of selection
		
		--set the new location of the graphic - you'll have to do the math yourself here
		set geometric bounds of graphic 1 of selection to {tf, lg, bg, rg}
	end tell
end tell

run this with a placed image selected, not the picture box.

tell application "Adobe InDesign CS2"
	set x to selection
	set x1 to item 2 of geometric bounds of parent of item 1 of x --get horizontal origin of box
	set y1 to item 1 of geometric bounds of parent of item 1 of x --get vertical origin of box 
	set w1 to (item 4 of geometric bounds of item 1 of x) - (item 2 of geometric bounds of item 1 of x) -- get width of image
	set h1 to (item 3 of geometric bounds of item 1 of x) - (item 1 of geometric bounds of item 1 of x) --get height of image
	set geometric bounds of item 1 of x to {y1, x1, y1 + h1, x1 + w1}
end tell

This could be cleaned up and calles to ID consolidated for increased performance but this makes it pretty clear what I am doing. Basically you need to get the origin of the parent (rectangle…aka. picture box) then the width and height of the image and reset the visible bounds based on these coordinates.

Thanks! I have figured it out what I needed to do.