0 Replies Latest reply on Jun 27, 2009 9:53 PM by macian2

    (AS) Adding Column Rules to multi-column text box

    macian2 Level 1

      I am submitting this script to everyone, in the hope that others modify with cleaner script than mine. This applescript will work in Adobe InDesign CS3. I may have gone a little overboard on the global statements...but this script does work!

      It was designed to add column rules to a two, three, four, or five multi-column text box. If any one can improve the script...great! Maybe someone can translate into javascript also.

       

      (* Add Column Rules.scpt *)

       

      global theDoc
      global theSel
      global thePage
      global tp
      global lft
      global bot
      global rt
      global insetTop
      global insetLeft
      global insetBot
      global insetRight
      global theColCount
      global myObjWidth
      global myObjCenter
      global myColGut
      global oneColWidth
      global myStrokeColor
      global myStrokeWeight
      --=================

       

      tell application "Adobe InDesign CS3"
         
          --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 if
          set theDoc to active document
         
          --CHECK IF ANY SELECTION HAS BEEN MADE
          try
              set theSel to object reference of selection
          on error
              beep
              display dialog "Opps . . . no selection was made!" buttons {"Opps!"} default button 1 with icon 1 giving up after 10
              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 dialog "Opps . . . you selected more than one item. Please try again..." buttons {"Opps!"} default button 1 with icon 1 giving up after 10
              select nothing
              return
          end if
         
          --CHECK IF THE SELECTION IS TEXT BOX
          if content type of theSel is not text type then
              beep
              display dialog "Opps . . . your selection is not a \"text\" box." buttons {"Opps!"} default button 1 with icon 1 giving up after 10
              select nothing
              return
          end if
         
          --SET COLOR CHOICE FOR STROKE RULE
          set myStrokeColor to "Black" --normal spot color use
          set myStrokeWeight to "0.75 pt"
         
          -- GET GEOMETRIC BOUNDS OF THE SELECTION (used to reset zero point location)
          set zero1 to (item 1 of (geometric bounds of theSel)) -- y1
          set zero2 to (item 2 of (geometric bounds of theSel)) -- x1
         
          set zero point of theDoc to {zero2, zero1} --SET THE ZERO POINT RULER TO TOP/LEFT EDGE
         
          -- GET CURRENT UNIT OF MEASURE SETTINGS BEFORE ADDING LINE
          set {oldHorz, oldVert} to {horizontal measurement units of view preferences, vertical measurement units of view preferences}
         
          -- SET THE NEW UNIT OF MEASURE
          set the properties of view preferences to {horizontal measurement units:points, vertical measurement units:points, ruler origin:page origin}
         
          -- GET NEW GEOMETRIC BOUNDS OF THE SELECTION
          set tp to (item 1 of (geometric bounds of theSel)) -- y1
          set lft to (item 2 of (geometric bounds of theSel)) -- x1
          set bot to (item 3 of (geometric bounds of theSel)) -- y2
          set rt to (item 4 of (geometric bounds of theSel)) -- x2
         
          -- GET INSET SPACING OF THE SELECTION
          set insetTop to (item 1 of inset spacing of text frame preferences of theSel)
          set insetLeft to (item 2 of inset spacing of text frame preferences of theSel)
          set insetBot to (item 3 of inset spacing of text frame preferences of theSel)
          set insetRight to (item 4 of inset spacing of text frame preferences of theSel)
         
          --GET OTHER SPECS
          set myObjWidth to (rt - lft)
          set theColCount to (get text column count of text frame preferences of theSel)
          set myColGut to (get text column gutter of text frame preferences of theSel)
          set oneColWidth to (get text column fixed width of text frame preferences of theSel)
          set myObjCenter to (myObjWidth / 2)
         
          --MAKE COLUMN RULES
          if theColCount = 1 then
              my zeroColCount()
          else if theColCount = 2 then
              my twoColumnRule()
          else if theColCount = 3 then
              my threeColumnRule()
          else if theColCount = 4 then
              my fourColumnRule()
          else if theColCount = 5 then
              my fiveColumnRule()
          end if
         
          -- RESET THE UNIT OF MEASURE TO ORIGINAL SETTING
          set the properties of view preferences to {horizontal measurement units:oldHorz, vertical measurement units:oldVert}
         
          --RETURN ZERO POINT TO ORIGINAL 0,0
          set zero point of theDoc to {0, 0}
         
          --delay 1
          beep 2
          select nothing
         
      end tell --app
      {theColCount, myObjWidth, myObjCenter, myColGut, oneColWidth, myStrokeWeight}

       

      --=======================
      --HANDLERS
      --=======================

       

      on zeroColCount()
          tell application "Adobe InDesign CS3"
              activate
              beep
              display dialog "Opps! ... Your selection should be a" & return & "multi-column text box with" & return & "two, or three, or four columns." buttons "Okay..." default button 1 with icon 1 giving up after 5
          end tell --application
      end zeroColCount

       

      on twoColumnRule()
          tell application "Adobe InDesign CS3"
              activate
              -- MAKE A GRAPHIC RULE
              --calculate data
              set cRuleTop to (tp + insetTop)
              set cRuleBot to (bot - insetBot)
             
              tell thePage
                  make graphic line with properties {geometric bounds:{cRuleTop, myObjCenter, cRuleBot, myObjCenter}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
              end tell --thePage
          end tell --application
      end twoColumnRule

       

      on threeColumnRule()
          tell application "Adobe InDesign CS3"
              activate
              -- MAKE A GRAPHIC RULE
              --calculate data
              set colWidthHalf to (oneColWidth / 2)
              set colGutHalf to (myColGut / 2)
              set cRule1left to (myObjCenter - colWidthHalf - colGutHalf)
              set cRule1right to (myObjCenter + colWidthHalf + colGutHalf)
              set cRuleTop to (tp + insetTop)
              set cRuleBot to (bot - insetBot)
             
              tell thePage
                  --first graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1left, cRuleBot, cRule1left}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --second graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1right, cRuleBot, cRule1right}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
              end tell --thePage
          end tell --application
      end threeColumnRule

       

      on fourColumnRule()
          tell application "Adobe InDesign CS3"
              activate
              -- MAKE A GRAPHIC RULE
              --calculate data
              set colWidthHalf to (oneColWidth / 2)
              set colGutHalf to (myColGut / 2)
              set cRule1left to (myObjCenter - colGutHalf - oneColWidth - colGutHalf)
              set cRule1right to (myObjCenter + colGutHalf + oneColWidth + colGutHalf)
              set cRuleTop to (tp + insetTop)
              set cRuleBot to (bot - insetBot)
             
              tell thePage
                  --first graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, myObjCenter, cRuleBot, myObjCenter}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --second graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1left, cRuleBot, cRule1left}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --third graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1right, cRuleBot, cRule1right}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
              end tell --thePage
          end tell --application
      end fourColumnRule

       

      on fiveColumnRule()
          tell application "Adobe InDesign CS3"
              activate
              -- MAKE A GRAPHIC RULE
              --calculate data
              set colWidthHalf to (oneColWidth / 2)
              set colGutHalf to (myColGut / 2)
              set cRule1left to (myObjCenter - colWidthHalf - colGutHalf)
              set cRule2left to (myObjCenter - colWidthHalf - myColGut - oneColWidth - colGutHalf)
              set cRule1right to (myObjCenter + colWidthHalf + colGutHalf)
              set cRule2right to (myObjCenter + colWidthHalf + myColGut + oneColWidth + colGutHalf)
              set cRuleTop to (tp + insetTop)
              set cRuleBot to (bot - insetBot)
             
              tell thePage
                  --first graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1left, cRuleBot, cRule1left}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --second graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule2left, cRuleBot, cRule2left}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --third graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule1right, cRuleBot, cRule1right}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
                  --fourth graphic column rule
                  make graphic line with properties {geometric bounds:{cRuleTop, cRule2right, cRuleBot, cRule2right}, stroke weight:myStrokeWeight, stroke color:myStrokeColor, name:"DividerRule"}
              end tell --thePage
          end tell --application
      end fiveColumnRule