Jerome,
Unfortunately the scale of the placed image will not be consistent.
The format being placed will always be PDF.
I have tried other methods very similar to what you have mentioned. The problem is, I really need the ability to scale upon place, since I could never trust an operator to crop the selection to the text and/or graphics to the exact pixel bounds in InDesign, which is where it all begins.
The entire script is copying a selection in InDesign, pasting the selection to a new document that is 50 pts. larger than the selection (in order to account for text ascenders and descenders). That document is then exported as a PDF. - I tried the jpeg route, but pasted text frames within other frames, yielded issues. - PDF or EPS seemed the most consistent.
The entire script is below (please pardon my poor scripting):
tell application "InDesign CS"
copy
set sel to the selection
set theDoc to active document
set theName to "ExportedImage"
set thePath to "Macintosh HD:Users:admin:Desktop:WorkInProgress:ExportedImage:"
set filePath to thePath & theName & ".pdf"
end tell
set DocBounds to {0, 0, 0, 0}
tell application "InDesign CS"
try
set SelectionBounds to visible bounds of selection
set DocBounds to SelectionBounds
set DocHeight to ((item 3 of DocBounds) - (item 1 of DocBounds))
set DocWidth to ((item 4 of DocBounds) - (item 2 of DocBounds))
--return {DocHeight, DocWidth}
end try
end tell
set DocBounds to {0, 0, 0, 0}
tell application "InDesign CS"
try
set SelectionBounds to visible bounds of selection
repeat with i from 1 to count of SelectionBounds
if DocBounds is {0, 0, 0, 0} then
set DocBounds to item i of SelectionBounds
else
if item 1 of item i of SelectionBounds < item 1 of DocBounds then set item 1 of DocBounds to item 1 of item i of SelectionBounds
if item 2 of item i of SelectionBounds < item 2 of DocBounds then set item 2 of DocBounds to item 2 of item i of SelectionBounds
if item 3 of item i of SelectionBounds > item 3 of DocBounds then set item 3 of DocBounds to item 3 of item i of SelectionBounds
if item 4 of item i of SelectionBounds > item 4 of DocBounds then set item 4 of DocBounds to item 4 of item i of SelectionBounds
end if
end repeat
set DocHeight to ((item 3 of DocBounds) - (item 1 of DocBounds))
set DocWidth to ((item 4 of DocBounds) - (item 2 of DocBounds))
end try
end tell
--return {DocHeight, DocWidth}
if DocWidth is greater than DocHeight then
tell application "InDesign CS"
set theDoc to make document
tell view preferences of theDoc
set horizontal measurement units to points
set vertical measurement units to points
set ruler origin to page origin
end tell
tell document preferences of theDoc
set properties to {page height:(DocHeight) + "50", page width:(DocWidth) + "50", page orientation:landscape, pages per document:1, column guide color:gray}
end tell
tell margin preferences of page 1 of theDoc
set properties to {column count:1, column gutter:12, top:0, left:0, bottom:0, right:0}
end tell
end tell
end if
if DocWidth is less than or equal to DocHeight then
tell application "InDesign CS"
set theDoc to make document
tell view preferences of theDoc
set horizontal measurement units to points
set vertical measurement units to points
set ruler origin to page origin
end tell
tell document preferences of theDoc
set properties to {page height:(DocHeight) + "50", page width:(DocWidth) + "50", page orientation:portrait, pages per document:1, column guide color:gray}
end tell
tell margin preferences of page 1 of theDoc
set properties to {column count:1, column gutter:12, top:0, left:0, bottom:0, right:0}
end tell
end tell
end if
tell application "InDesign CS"
paste
export theDoc format PDF type to filePath without showing options
close theDoc
tell application "Adobe Photoshop CS"
with timeout of 300 seconds
activate
make new document with properties {height:103, width:155}
end timeout
end tell
tell application "System Events"
tell process "Adobe Photoshop CS"
click menu item "Place..." of menu "File" of menu bar 1
end tell
end tell
end tell