Article View: adobe.scripting.indesign
Article #16042[AS] Preflight script to scale images... geometric bounds not working
From: Nathan_Banka
Date: Thu, 23 Oct 2003 17:04
Date: Thu, 23 Oct 2003 17:04
93 lines
4004 bytes
4004 bytes
I'm writing an applescript to go through all our images and scale them in Photoshop, then relink them (first real applescript, except the obligatory prank scripts). The problem is that when I try to move the image with geometric bounds(the picture moves around when I scale it up to 100%), I get an error; it says it cannot set those geometric bounds.
Here's the script:
tell application "InDesign 2.0.2"
activate
set myDocument to active document
tell myDocument
set outdateLinks to every link whose status is link out of date
repeat with OODLinks from 1 to (count outdateLinks)
update link of item OODLinks of outdateLinks
end repeat
set IDLinks to every link whose status is normal
repeat with myCounter from 1 to (count IDLinks)
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
select theFrame
set theProps to properties of item 1 of selection
set theProps to {absolute horizontal scale:none, horizontal scale:100, absolute vertical scale:none �
, vertical scale:100} & theProps
--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
--get the scale
set myHoriz to horizontal scale of theImage as real
set myVert to vertical scale of theImage as real
repeat
set theClass to class of parent of theFrame
if theClass = spread then
set theSpread to parent of theFrame
exit repeat
else
set theFrame to parent of theFrame
end if
end repeat
--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)
set theClass to class of theImage
repeat
if myHoriz is not 100 and myHoriz = myVert then
--scale them 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
--now to update the link in Indesign...
activate
set Altereds to (every link whose status is link out of date)
if (count Altereds) is greater than 1 then
--we want to update and rescale every instance of the image
repeat with cAlts from 1 to (count Altereds)
update link of item cAlts of Altereds
set altImage to parent of item cAlts of Altereds
set altFrame to parent of altImage
repeat
set altClass to class of parent of altFrame
if altClass = spread then
set altSpread to parent of altFrame
exit repeat
else
set altFrame to parent of altFrame
end if
end repeat
set properties of altFrame to theProps
set properties of altImage to {geometric bounds:ImgPos}
end repeat
exit repeat
else
update link of item myCounter of IDLinks
set properties of theFrame to theProps
set properties of theImage to {geometric bounds:ImgPos}
end if
else
exit repeat
end if
end repeat
end repeat
end tell
end tell
Technical Details
Message-ID:
<2ccdf3b1.-1@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webxShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f939a,bcc0c6dca106f772,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-10-23 10:07:55 PST From: Nathan_Banka@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: [AS] Preflight script to scale images... geometric bounds not working Message-ID: <2ccdf3b1.-1@webx.la2eafNXanI> Date: Thu, 23 Oct 2003 10:04:24 -0700 Lines: 98 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit