Article View: adobe.scripting.indesign
Article #16045Re: [AS] Preflight script to scale images... geometric bounds not working
From: Olav_Kvern
Date: Thu, 23 Oct 2003 21:07
Date: Thu, 23 Oct 2003 21:07
64 lines
4226 bytes
4226 bytes
Nathan--
I've reworked your script a bit to demonstrate a few tricks of InDesign links management I've picked up over the years. This version seems to do what you want it to do--scales the images in Photoshop and then resets the scaling of both image and frame to 100% while retaining the original position of the image and the frame on the page (though the stroke on the frame may change because of the scaling changes).
I'm assuming that you wrote the script for a specific publication type--if it's for a more general publication, note that there is a logical error in the design of the script.
The original script (and the rewritten one) both assume that multiple images in the document will all have the same scaling. In a more general case, one instance of the image might be scaled to 50%, another might be 75%. Since we're saving over the original file, we'll get one or the other of those scalings--whichever comes first--in the file scaled by Photoshop. It would probably be better to save to a new file name and then update the link to that file name. By adding the scaling percentage to the new file name ("myImage_50.tif" from an original file name "myImage.tif", for example), we can even keep from creating multiple files of the same scaling percentage.
set myProcessedLinks to {}
tell application "InDesign 2.0.2"
set myDocument to active document
tell myDocument
set outdateLinks to every link whose status is link out of date
repeat with OODLinks from (count outdateLinks) to 1 by -1
update link of item OODLinks of outdateLinks
end repeat
set IDLinks to every link whose status is normal
--Iterate backwards through the links to avoid invalidating objects.
repeat with myCounter from (count IDLinks) to 1 by -1
set LinkName to name of item myCounter of IDLinks as string
set theImage to parent of item myCounter of IDLinks
set theFrame to parent of theImage
--get the path
set ImagePath to file path of item myCounter of IDLinks as string
--get the image's location
set ImgPos to geometric bounds of theImage
set FramePos to geometric bounds of theFrame
--get the scale
set myHoriz to horizontal scale of theImage as real
set myVert to vertical scale of theImage as real
--get the bounds of the image
set myY1 to (item 1 of ImgPos)
set myX1 to (item 2 of ImgPos)
set myY2 to (item 3 of ImgPos)
set myX2 to (item 4 of ImgPos)
--If the image has been scaled to something other than 100%,
--and if it has not already been resized in photoshop...
if myHoriz is not 100 and myHoriz = myVert and ImagePath is not in myProcessedLinks then
--...then scale the graphic in Photoshop:
tell application "Adobe Photoshop 7.0"
--activate
open file ImagePath
set docRef to current document
resize image docRef width myHoriz as percent resample method none
close docRef with saving
end tell
end if
--When you update the link, the old link is destroyed
--and InDesign returns the new link.
set myLink to update link of item myCounter of IDLinks
set theImage to parent of myLink
set theFrame to parent of theImage
set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
copy ImagePath to end of myProcessedLinks
end repeat
end tell
end tell
Thanks,
Ole
Technical Details
Message-ID:
<2ccdf3b1.0@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccdf3b1.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,bcc0c6dca106f772 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-10-23 14:07:57 PST From: Olav_Kvern@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: [AS] Preflight script to scale images... geometric bounds not working Message-ID: <2ccdf3b1.0@webx.la2eafNXanI> Date: Thu, 23 Oct 2003 14:07:17 -0700 References: <2ccdf3b1.-1@webx.la2eafNXanI> Lines: 80 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit