Strange InDesign script misbehavior
Strange InDesign script misbehavior
- Subject: Strange InDesign script misbehavior
- From: Roy McCoy <email@hidden>
- Date: Fri, 12 Jun 2009 12:26:52 +0200
Rick Gordon posted the guides-to-lines CS3 script below (also at http://files.getdropbox.com/u/1107821/Convert guides to lines.scpt)
on the Lasso InDesign list, saying that it worked for him (CS3
5.0.4, OS X 10.4.11) on a variety of test files. It doesn't work for
me in Leopard, however, with either CS3 or CS4. The guides list is
always okay, but the lines list always winds up empty. On looking into
this I found that if I insert a beep immediately before "set vWidth to
page width of vPage" I hear it if there's a guide on the page, but
only once regardless of how many guides there are. If I place the beep
immediately after the same line, I don't hear it at all. So that
assignment line seems to be somehow making the script kick out of both
the tell vItem statement and the repeat containing it. I don't,
however, see any evident reason for this. Can anyone explain the
mystery to me and perhaps suggest a way of dealing with it? The script
isn't important to me as I don't want or need to convert InDesign
guides to lines, but a similar problem may come up again and I'd like
to know how to handle it if it does.
Thanks,
Roy McCoy
Rotterdam, NL
--
property pSelectionChoice : "Selection"
property pActivePageChoice : "Active Page (page listed in window
footer)"
property pActiveSpreadChoice : "Active Spread"
property pDefaultChoice : pActiveSpreadChoice
property pUIColorList : {"light blue", "red", "green", "blue",
"yellow", "magenta", "cyan", "gray", "black", "orange", "dark green",
"teal", "tan", "brown", "violet", "gold", "dark blue", "pink",
"lavender", "brick red", "olive green", "peach", "burgundy", "grass
green", "ochre", "purple", "light gray", "charcoal", "grid blue",
"grid orange", "fiesta", "light olive", "lipstick", "cute teal",
"sulphur", "grid green", "white"}
property pRGBList : {{79, 153, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0,
255}, {255, 255, 79}, {255, 79, 255}, {0, 255, 255}, {128, 128, 128},
{0, 0, 0}, {255, 102, 0}, {0, 84, 0}, {0, 153, 153}, {204, 153, 102},
{153, 51, 0}, {153, 51, 255}, {255, 153, 0}, {0, 0, 135}, {255, 153,
204}, {153, 153, 255}, {153, 0, 0}, {102, 102, 0}, {255, 153, 153},
{153, 0, 51}, {153, 204, 0}, {153, 102, 0}, {102, 0, 102}, {186, 186,
186}, {171, 163, 181}, {122, 186, 217}, {255, 181, 107}, {247, 89,
107}, {140, 166, 107}, {207, 130, 181}, {130, 207, 194}, {207, 207,
130}, {156, 222, 156}, {255, 255, 255}}
property pLabelMarker : "#"
global gColorListLength
set gColorListLength to length of pUIColorList
set vLineWidth to 0.25
set vMaxThreshold to 4000
set vGuideList to {}
set vLineList to {}
try
set vResult to item 1 of (choose from list {pSelectionChoice,
pActivePageChoice, pActiveSpreadChoice} default items {pDefaultChoice}
without multiple selections allowed and empty selection allowed)
set pDefaultChoice to vResult
on error
return
end try
tell application "Adobe InDesign CS3"
tell active document
set vDoc to it
set vOriginalZeroPoint to zero point
set zero point to {0, 0}
tell view preferences
set vOriginalRulerOrigin to ruler origin
set ruler origin to spread origin
end tell
try
set vActiveSpread to active spread of layout window 1
set vActivePage to active page of layout window 1 --i.e., the page
whose number shows in the window footer
tell document preferences
set vTopBleed to document bleed top offset
set vBottomBleed to document bleed bottom offset
set vInsideOrLeftBleed to document bleed inside or left offset
set vOutsideOrRightBleed to document bleed outside or right offset
end tell
if vResult is pSelectionChoice then
set vTarget to selection
set vGuideList to vTarget
if length of vGuideList is 0 then
tell me to display alert "Nothing was selected." buttons {"OK"}
default button "OK"
return
end if
else
if vResult is pActivePageChoice then
set vTarget to vActivePage
else if vResult is pActiveSpreadChoice then
set vTarget to vActiveSpread
end if
set vGuideList to every guide of vTarget
if length of vGuideList is 0 then
tell me to display alert "There are no guides to be operated on."
buttons {"OK"} default button "OK"
return
end if
end if
set vPagesOnSpread to count items of pages of vActiveSpread
set vSpread to vActiveSpread
repeat with vItem in vGuideList
tell vItem
set vPage to parent
set vOriginalViewThreshold to view threshold as text
if class of vPage is not page then
set vPage to page 1 of vDoc
end if
set vWidth to page width of vPage
set vBottom to page height of vPage
set vTop to 0
set vLeft to 0
set vRight to vWidth
if fit to page is false then
set vWidth to vWidth * vPagesOnSpread
set vTop to vTop - vTopBleed
set vBottom to vBottom + vBottomBleed
set vRight to vWidth
set vLeft to vLeft - vInsideOrLeftBleed
set vRight to vRight + vOutsideOrRightBleed
else --i.e., fit to page is true
set vLeft to item 2 of bounds of vPage
set vRight to vLeft + vWidth
end if
if orientation is horizontal then
set vTop to location
set vBottom to location
else --i.e., orientation is vertical
set vLeft to location
set vRight to location
end if
set vLineColor to my fMapUIColorsToRGB(guide color as text, vDoc)
set label to pLabelMarker & vOriginalViewThreshold
set vGuideID to id as text
if fit to page is true then
set vTarget to vPage
else
set vTarget to vSpread
end if
tell vTarget
set end of vLineList to make new graphic line with properties
{stroke weight:vLineWidth, stroke color:vLineColor, stroke
alignment:center alignment, stroke type:"Solid", geometric bounds:
{vTop, vLeft, vBottom, vRight}, label:pLabelMarker & vGuideID,
locked:true}
end tell
set view threshold to vMaxThreshold
end tell
end repeat
end try
tell view preferences to set ruler origin to vOriginalRulerOrigin
set zero point to vOriginalZeroPoint
return {vGuideList, vLineList}
end tell
end tell
on fMapUIColorsToRGB(aConstant, aDocumentObjectRef)
tell application "Adobe InDesign CS3"
tell aDocumentObjectRef
repeat with i from 1 to gColorListLength
tell item i of pUIColorList
if contents is aConstant then exit repeat
end tell
end repeat
set vMatchedColor to item i of pRGBList
try
set vLineColor to make new color with properties {model:process,
space:RGB, color value:vMatchedColor, name:aConstant,
label:pLabelMarker & "GuidesToLines"}
on error
set vLineColor to color aConstant
end try
return vLineColor
end tell
end tell
end fMapUIColorsToRGB
--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden