INDESIGN CS - Placed image name and scale?

Having been away from scripting for a few months I’ve found that I’ve completely forgotten how to get some image properties into a text box.
Could some please tell me how to get an image’s name and scale before moving on to place another image?

I’d like to do this as the repeat loop executes so the image is placed and sized (which I fortunately figured out pretty quickly), and then a text box is created below it with the image name and scale.

thanks in advance,
:confused: aaron

I can’t remeber how to get the image scale offhand - but this will demonstarte getting the image name and should get you started.

tell application "Adobe InDesign CS"
	activate
	tell active document
		set myrectangles to (every rectangle)
		repeat with t in myrectangles
			set theImageList to all graphics of t
			repeat with i from 1 to (count theImageList)
				set theImageName to get name of item link of (item i of theImageList) as string
				display dialog theImageName
			end repeat
		end repeat
	end tell
end tell

Here is a script I am in the middle of tweaking, that creates a text frame with the name and scale % of each image in an InDesignCS2 file. Right now it places all the text frames in the top left corner on top of each other, but the script does return the image name and scale. I assume the terms are the same for CS2 and CS1?

Hope this helps! =)

tell application "Adobe InDesign CS2"
	
	tell active document
		set IDLinks to links
		repeat with myCounter from 1 to (count IDLinks)
			try
				set LinkName to name of item myCounter of IDLinks as string
				set theImage to parent of item myCounter of IDLinks
				set horScale to horizontal scale of theImage as string
			end try
			
			set myLayer to make text frame
			set geometric bounds of myLayer to {0, 0, 0.4, 9}
			set contents of myLayer to ((LinkName) & "  Scaled @ " & (horScale) & "%")
		end repeat
		
	end tell
end tell

This is not my code, but I modified it slightly to try and answer your need for the image name and scaling:


tell application "Adobe InDesign CS2"
	tell document 1
		set imageList to links
		repeat with i in imageList
			set imageStats to name of i & " - " & (horizontal scale of parent of i as integer)
			set theFrame to parent of parent of i
			set geobounds to geometric bounds of theFrame
			make text frame at end with properties {geometric bounds:{(item 3 of geobounds) + 0.014, item 2 of geobounds, (item 3 of geobounds) + 0.25, item 4 of geobounds}, contents:imageStats, applied font:"Verdana"}
			tell text frame -1
				set properties of paragraph 1 to {applied font:"Verdana"}
			end tell
			make group with properties {group items:{theFrame, text frame -1}}
		end repeat
	end tell
end tell

The caption text box is created for each image (right under it) and then grouped with it. Let me know if that works for you.

Hiya,
I haven’t been able to do any scripting for a while so I’ve just gotten back to this. Originally I was making a script that scattered loose images from scratch so I was interested in labeling the images as they were laid up on the page, not afterwards. However I’ve lost the script, which worked pretty well, so doing the text label in the loop isn’t an issue now.

Thank you all so much for the script samples; I appreciate the help. I ended up modifying a script I had found some time ago and it’s appearently working ok.

mleslie, your script was failing on multiple page documents, but it helped me figure out how to get the scaling factor. Thanks again to all (and kai for some previous date coercion stuff in other threads.) Here’s the script that appears to work for me, except that I haven’t quite figured out how to get it to tighten the kerning up to always fit in the label box.


set {month:m, day:d, year:y} to (current date)
set theDate to (m * 1 & "." & d & "." & y) as string
log theDate

tell application "InDesign CS"
	tell document 1
		tell view preferences
			set horizontal measurement units to points
			set vertical measurement units to points
		end tell
		
		try
			set labelStyle to make character style with properties {name:"Mononoko", applied font:"Monaco", font style:"Regular", point size:10, fill color:"Black"}
		on error
			set labelStyle to make character style with properties {name:"Mononoko", applied font:"Monaco", font style:"Regular", point size:10, fill color:"Black"}
		end try
		--myLinksName is the name of the layer containing the links tags.
		set myLinksName to "Links Names"
		try
			--Get the layer on which to place the links tags.
			set myLayer to layer myLinksName
		on error
			--Create the layer if it didn't already exist.
			set myLayer to make layer at beginning with properties {name:myLinksName}
		end try
		repeat with i from 1 to count of links
			set imageClass to class of parent of link i
			if imageClass is in {PDF, image, EPS} then
				set picFrame to parent of parent of link i
				set LinkName to name of link i
				set imageStats to horizontal scale of parent of link i
				set linkNameLen to length of LinkName
				set theBounds to geometric bounds of picFrame
				set theBounds to {(item 3 of theBounds) + 2, item 2 of theBounds, (item 3 of theBounds) + 20, (item 4 of theBounds) + linkNameLen + 26}
				repeat
					set theClass to class of picFrame
					if theClass is in {page, spread} then
						set theTarget to picFrame
						exit repeat
					else if theClass is in {character, text, insertion point} then --
						inline
						set picFrame to parent text frame of character 1 of picFrame
					else
						set picFrame to parent of picFrame
					end if
				end repeat
				set labelFrame to make text frame at theTarget with properties {geometric bounds:theBounds, label:"Pic label", contents:{LinkName & " @ " & imageStats & "%" & "  " & theDate} as text, item layer:myLayer, text wrap preferences:«constant tilpnone»}
				set properties of text frame preferences of labelFrame to {inset spacing:{"0p1", "0p1", "0p2.5", "0p1"}, vertical justification:«constant cnalcent», ignore wrap:true}
				
			end if
		end repeat
	end tell
	beep
	with timeout of 30 seconds
		display dialog "May You Always Know What Image Is Placed." buttons {"OK"} default button 1
	end timeout
end tell

:confused: aaron