Article View: adobe.scripting.indesign
Article #15669Re: [AS] Preflight script to scale images... geometric bounds not working
From: Kari_Puikkonen
Date: Thu, 20 Nov 2003 12:23
Date: Thu, 20 Nov 2003 12:23
160 lines
7464 bytes
7464 bytes
I'm constantly surprised what you can do with AppleScript. This script which is combined from Ole's and Rob Day's scripts do the trick:
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign 2.0.2"
set myDocument to active document
tell myDocument
--If the measurement units of the active document are not inches, set the
--measurement units to inches. Units MUST be inches in order to script work.
if horizontal measurement units of view preferences of myDocument is not inches or vertical measurement units of view preferences of myDocument is not inches then
set myOldViewPreferences to properties of view preferences of myDocument
set horizontal measurement units of view preferences of myDocument to inches
set vertical measurement units of view preferences of myDocument to inches
set myResetUnits to true
else
set myResetUnits to false
end if
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 myLink to item myCounter of IDLinks
--Process only image links.
set myLinkType to link type of myLink
--If statement could be expanded to include other image types.
if myLinkType = "TIFF" or myLinkType = "JPEG" or myLinkType = "photoshop format" then
set LinkName to name of myLink
set theImage to parent of myLink
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 rotation angle
set myRotation to absolute rotation angle of theImage
--get the scale
set myHoriz to absolute horizontal scale of theImage
set myVert to absolute vertical scale of theImage
set myHorizFrameHeight to absolute horizontal scale of theFrame
set myVertFrameWidth to absolute vertical scale of theFrame
set boxRight to item 4 of FramePos
set boxleft to item 2 of FramePos
set boxTop to item 1 of FramePos
set boxBottom to item 3 of FramePos
set boxHeight to boxBottom - boxTop
set boxWidth to boxRight - boxleft
set picX1 to item 2 of ImgPos
set picY1 to item 1 of ImgPos
set picX2 to item 4 of ImgPos
set picY2 to item 3 of ImgPos
set picXCenter to picX1 + ((picX2 - picX1) / 2)
set picYCenter to picY1 + ((picY2 - picY1) / 2)
set boxX1 to item 2 of FramePos
set boxY1 to item 1 of FramePos
set boxX2 to item 4 of FramePos
set boxY2 to item 3 of FramePos
set boxXCenter to boxX1 + ((boxX2 - boxX1) / 2)
set boxYCenter to boxY1 + ((boxY2 - boxY1) / 2)
set hOff to picXCenter - boxXCenter
set vOff to picYCenter - boxYCenter
--If the image has been scaled to something other than 100%,
--and if it has not already been resized in photoshop...
if myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth and ImagePath is not in myProcessedLinks then
set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
--...then scale the graphic in Photoshop:
tell application "Adobe Photoshop 7.0"
activate
set ruler units of settings to inch units
open file ImagePath
set docRef to current document
resize image docRef width percent myHoriz resample method none
resize image docRef resolution 300 resample method bicubic
tell docRef
select all
copy
paste
set name of layer "Layer 1" to "Photo"
delete layer "Background"
resize canvas width boxWidth height boxHeight
rotate layer "Photo" angle -myRotation
end tell
tell layer "Photo" of docRef
translate delta x hOff
translate delta y vOff
end tell
tell docRef
flatten
end tell
--If...else if statement could be expanded to handle other file types.
if myLinkType = "TIFF" then
set myImageDocument to save docRef in file myNewFileName as TIFF
else if myLinkType = "JPEG" then
set myImageDocument to save docRef in file myFileName as JPEG
else if myLinkType = "photoshop format" then
set myImageDocument to save docRef in file myFileName as Photoshop format
end if
set myFileName to file path of myImageDocument
--close docRef with saving
close current document saving no
end tell
relink myLink to myFileName
--When you update the link, the old link is destroyed
--and InDesign returns the new link.
set myLink to update myLink
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}
fit theFrame given proportionally
copy myFileName to end of myProcessedLinks
else if ImagePath is in myProcessedLinks then
set myLink to update myLink
end if
end if
end repeat
--Resets the units
if myResetUnits is true then
tell view preferences of myDocument to set properties to myOldViewPreferences
end if
end tell
end tell
on myMakeFileName(myFolder, myFile, myHoriz)
set myFileInfo to info for myFile
set myFileName to name of myFileInfo
set myFolderName to myFolder as string
if (myHoriz as string) contains "," then
set myOldDelimiters to text item delimiters
set text item delimiters to ","
set myHoriz to text item 1 of (myHoriz as string)
set text item delimiters to myOldDelimiters
end if
if myFileName contains "," then
set myOldDelimiters to text item delimiters
set text item delimiters to ","
set myFileName to text item 1 of myFileName
set text item delimiters to myOldDelimiters
end if
set myNewFileName to myFileName & "_" & (myHoriz as string)
set myNewFilePath to myFolderName & myNewFileName
return myNewFilePath
end myMakeFileName
And now the biggest question of all:
What do I have to change in order to get this script to work with the InDesign CS and the Photoshop CS!?
Kari
Technical Details
Message-ID:
<2ccdf3b1.19@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-11-20 04:37:40 PST From: Kari_Puikkonen@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.19@webx.la2eafNXanI> Date: Thu, 20 Nov 2003 04:23:26 -0800 References: <2ccdf3b1.-1@webx.la2eafNXanI> Lines: 169 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit