CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
New (AS) for adding "Multi-Column Rules"
- This topic has 0 replies, 1 voice, and was last updated 15 years, 3 months ago by
Ian MacPherson.
-
AuthorPosts
-
-
July 31, 2010 at 10:58 am #56540
Ian MacPherson
MemberI have created a new way to add “Column Rules” to any multi-column text frame.
This is an Applescript file. I currently know little of Javascript.I will gladly accept all comments and improvement ideas.
I challenge all the “guru's” out there — if anyone could translate to Javascript,
this would be wonderfull. Then all InDesign users would benefit!I hope the following script will prove to be useful!
I currently have Adobe InDesign CS3, so I cannot say it will work perfectly
in another version; perhaps with some minor tweaks.The multi-column rules (lines) are perfectly centered in the designated gutters.
• Your text frame must be a multi-column text box.
• Your text frame may be placed anywhere on the active page.
• Your text frame must have a gutter more than 3.0 points.
• Your text frame can have any variable indents (top, bottom, left, right).
• The default column rule is .5 point, and can be modified through script file.I adapted and modified an earlier script found.
The script is as follows (copy and paste into your script editor of choice):
–== START OF SCRIPT — “ADD Column Rules”
(* Tested in Adobe InDesign CS3 only *)
global theDoc
global oldHorz
global oldVerttell application “Adobe InDesign CS3″
activatetry
set theSel to object reference of selection
end try–CHECK IF DOCUMENT IS OPEN
if (count documents) = 0 then
beep
display dialog “Please open a document and try again!” buttons {“Opps!”} default button 1 with icon 1 giving up after 10
return
end ifset theDoc to active document
–GET USERS CURRENT UNIT OF MEASURE SETTINGS
tell theDoc to set {oldHorz, oldVert} to {horizontal measurement units of view preferences, vertical measurement units of view preferences}–SET THE NEW UNIT OF MEASURE >> POINTS
tell theDoc to set the properties of view preferences to {horizontal measurement units:points, vertical measurement units:points, ruler origin:page origin}–CHECK IF ANY SELECTION HAS BEEN MADE
try
set theSel to object reference of selection
on error
beep
display alert “No Selection Was Made…” message “Opps… you forgot to make a selection!” & return & “Please try again and select a single “text frame”.” buttons {“Opps!”} default button 1 giving up after 10
run resetMeasureUnits
return
end try
set thePage to parent of selection–CHECK IF MORE THAN ONE ITEM IS SELECTED
if (count of theSel) ≥ 2 then
beep
display alert “More Than One Object Selected!” message “Opps… You have selected more than one item.” & return & “Please try again and select a single “text frame”.” buttons {“Opps!”} default button 1 giving up after 10
select nothing
run resetMeasureUnits
return
end if–CHECK IF THE SELECTION IS TEXT BOX
if content type of theSel is not text type then
beep
display alert “The selection is NOT a “Text” frame!” message “Opps… Your selection is not a “text” box.” & return & “Please select a single “Text Frame”” & return & “Try again…” buttons {“Opps!”} default button 1 giving up after 10
select nothing
run resetMeasureUnits
return
end if–CHECK IF THE SELECTED TEXT BOX IS A MULTI-COLUMN FRAME
if content type of theSel is not text type then
beep
display alert “The selection is NOT a “Text” frame!” message “Opps… Your selection is not a “text” box.” & return & “Please select a single “Text Frame”” & return & “Try again…” buttons {“Opps!”} default button 1 giving up after 10
select nothing
run resetMeasureUnits
return
end if–CHECK IF THE TEXT COLUMN GUTTER SPEC IS GREATER THAN 2.5 POINTS
if (text column gutter of text frame preferences of theSel is less than 3) then
beep
display alert “Text Column Gutter below minimum…” message “Opps… Your selection requires” & return & “the text column gutter to be” & return & “3+ points or greater.” & return & “Please try again…” buttons {“Opps!”} default button 1 giving up after 10
select nothing
run resetMeasureUnits
return
end if–GET OTHER SPEC'S
set oldMarginPrefs to properties of margin preferences of thePage
set oldColCount to (get column count of margin preferences of thePage)
set oldColGut to (get column gutter of margin preferences of thePage)tell theDoc
set theSel to object reference of selection–GET THE DOCUMENT MARGINS
set myPageWidth to get page width of document preferences as points
set myPageHeight to get page height of document preferences as points–GET PROPERTIES OF THE SELECTION
set gb1 to item 1 of (get geometric bounds of theSel) –top
set gb2 to item 2 of (get geometric bounds of theSel) –left
set gb3 to item 3 of (get geometric bounds of theSel) –bottom
set gb4 to item 4 of (get geometric bounds of theSel) –rightset colCount to text column count of text frame preferences of theSel
set colGut to text column gutter of text frame preferences of theSelset tfSpace1 to item 1 of (get inset spacing of text frame preferences of theSel)
set tfSpace2 to item 2 of (get inset spacing of text frame preferences of theSel)
set tfSpace3 to item 3 of (get inset spacing of text frame preferences of theSel)
set tfSpace4 to item 4 of (get inset spacing of text frame preferences of theSel)end tell –theDoc
set properties of margin preferences of thePage to {bottom:((myPageHeight – gb3) + tfSpace3), left:(gb2 + tfSpace2), right:((myPageWidth – gb4) + tfSpace4), top:(gb1 + tfSpace1), column count:colCount, column gutter:colGut}
–==============
run CenterColumnsRules
–==============–RESET THE USERS ORGINAL MARGIN PREFERENCES
set properties of margin preferences of thePage to oldMarginPrefs–RESET THE USERS ORIGINAL UNIT OF MEASURE SETTING
tell theDoc to set the properties of view preferences to {horizontal measurement units:oldHorz, vertical measurement units:oldVert, ruler origin:page origin}select nothing
end tell –app
–==========
– HANDLERS
–==========script resetMeasureUnits
tell application “Adobe InDesign CS3″
–RESET THE USERS ORIGINAL UNIT OF MEASURE SETTING
tell theDoc to set the properties of view preferences to {horizontal measurement units:oldHorz, vertical measurement units:oldVert}
end tell –app
end scriptscript CenterColumnsRules
property strokeWeight : “.5″ –points only
–property strokeWeight : missing value–Environment
try
set theDoc to getDocRef()
–call to handler
set {pageWid, pageHgt, topmar, leftMar, botmar, rightMar, colCount, colGut} to getPageParams(theDoc)
if colCount < 2 then
error “Requires page with columns”
end if
–makeLayer requires doc reference, name, visible and locked
set theLayer to makeLayer(theDoc, “Column Rules”, true, false)
set x1 to pageWid – rightMar
set cGutList to GetcGutterXList(leftMar, x1, colCount, colGut)
on error errStr
fatalMessage(errStr)
end try–Input
if strokeWeight is missing value then
set strokeWeight to measureEditbox()
end if–Process
tell application “Adobe InDesign CS3″
tell theDoc
set lineProperties to {stroke alignment:center alignment, stroke color:swatch “Black”, stroke type:”S
olid”, stroke weight:strokeWeight, item layer:theLayer, label:”ColumnRule”}
end tell –theDoc
tell active page of layout window 1
repeat with i from 1 to count of cGutList
set thisx to item i of cGutList
set theLine to make graphic line with properties {geometric bounds:{topmar, thisx, (pageHgt – botmar), thisx}} & lineProperties
end repeat
end tell –page
end tell –application
beep 1–===HANDLERS
(* Returns center x coordinate for each gutter on page. *)
on GetcGutterXList(x0, x1, numCol, gutWid)
set colXList to {}
set colwid to ((x1 – x0) – (gutWid * (numCol – 1))) / numCol
set stepValue to colwid + gutWid
set thiscolX to x0 + colwid + gutWid / 2
repeat with i from 2 to numCol
set end of colXList to thiscolX
set thiscolX to thiscolX + stepValue
end repeat
return colXList
end GetcGutterXList(* Returns list of essential page parameters. *)
on getPageParams(theDoc)
tell application “Adobe InDesign CS3″
set thePage to active page of layout window 1
tell document preferences of theDoc
set {pageWid, pageHgt} to {page width, page height}
end tell –app
tell margin preferences of thePage
set {topmar, leftMar, botmar, rightMar, colCount, colGut} to {top, left, bottom, right, column count, column gutter}
end tell –margin prefs
end tell –app
return {pageWid, pageHgt, topmar, leftMar, botmar, rightMar, colCount, colGut}
end getPageParams(*returns reference to active document. Will generate error if no document. *)
on getDocRef()
tell application “Adobe InDesign CS3″
if not (exists document 1) then
error “Requires active document with selected object”
else
return active document
end if
end tell –app
end getDocRef(*Creates layer if one by name is not in document;
moves it to bottom of layers. *)
on makeLayer(docRef, theName, theVisible, theLocked)
tell application “Adobe InDesign CS3″
tell docRef
if exists layer theName then
set theLayer to layer theName
if locked of theLayer is true then
set locked of theLayer to false
end if
else
set theLayer to make layer with properties {visible:theVisible, locked:theLocked, name:theName}
–In CS2 you need to move the layer to after layer -1 rather than end of layers
move theLayer to after layer 1
end if
end tell –docRef
end tell –app
return theLayer
end makeLayer–Gives user a message and cancels out of script
on fatalMessage(theMessage)
activate
display dialog theMessage buttons {“OK”} default button 1
error “User Error” number -128
end fatalMessage(* Creates measurement editbox in custom dialog *)
on measureEditbox()
set theContents to “”
tell application “Adobe InDesign CS3″
activate
set dialogRef to make dialog with properties {name:”Enter Rule Width”, can cancel:true}
tell dialogRef
tell (make dialog column)
tell (make border panel)
tell (make dialog column)
make static text with properties {static label:”Enter width for rule (points)”}
make static text with properties {static label:”Rule Width:”}
end tell –make dialog column
tell (make dialog column)
make static text with properties {static label:””}
set txtRef to (make measurement editbox with properties {edit contents:”.5″, edit units:points, minimum value:0.25, maximum value:12})
end tell –dialog column
end tell –border panel
end tell –dialog column
show
end tell –dialog ref
set dialogResult to result
if dialogResult is true then
set theResult to edit contents of txtRef
end if
–You will want to add the statement to destroy the dialog to remove it from memory as part of your script
destroy dialogRef
end tell –app
return theResult
end measureEditboxend script
–== END OF SCRIPT — “ADD Column Rules”
-
-
AuthorPosts
- You must be logged in to reply to this topic.
