Hi,
I have a script that takes search criteria from one FileMaker database and then searches another database. It gathers three things: article name, article body and graphic path. I also have properties that contain box bounds for text and graphics.
I know there is an easier way to put this script together with a repeat loop instead of having 8 scripts each, one set for gathering, one set for text and one set for graphic placement in Quark.
The reason I ask is that I have a lot more I want to add and it is already getting way out of hand.
Thanks!
Craig
--Layer
property layerNumber : "Layer 1"
--Graphic Boxes
property pictureBox1Back : {"82.049 pt", "54 pt", "164.613 pt", "166.759 pt"}
property pictureBox2Back : {"82.049 pt", "442.022 pt", "164.613 pt", "554.781 pt"}
property pictureBox3Back : {"256.182 pt", "180.425 pt", "338.746 pt", "293.184 pt"}
property pictureBox4Back : {"478.985 pt", "53.205 pt", "561.549 pt", "165.964 pt"}
property pictureBox5Back : {"478.985 pt", "53.205 pt", "561.549 pt", "165.964 pt"}
property pictureBox1Front : {"329.569 pt", "49.5 pt", "412.133 pt", "162.259 pt"}
property pictureBox2Front : {"448.436 pt", "267.615 pt", "531 pt", "380.374 pt"}
property pictureBox3Front : {"615.649 pt", "50.257 pt", "698.213 pt", "163.016 pt"}
--Article Boxes
property articleBoxBack1 : {"55 pt", "54 pt", "325.883 pt", "291.356 pt"}
property articleBoxBack2 : {"226.748 pt", "54 pt", "525.631 pt", "291.356 pt"}
property articleBoxBack3 : {"407.241 pt", "54 pt", "700.125 pt", "291.356 pt"}
property articleBoxBack4 : {"55 pt", "317.187 pt", "400.883 pt", "554.543 pt"}
property articleBoxBack5 : {"225.952 pt", "317.187 pt", "600.836 pt", "554.543 pt"}
property articleBoxFront1 : {"308.646 pt", "50.863 pt", "788 pt", "380.454 pt"}
property articleBoxFront2 : {"457.335 pt", "50.863 pt", "788 pt", "380.454 pt"}
property articleBoxFront3 : {"607.614 pt", "50.863 pt", "788 pt", "380.454 pt"}
global bot
--Make sure that Articles database is open - if not, open it
tell application "FileMaker Pro Advanced"
if not (exists database "LHP Articles.fp7") then
getURL "URL:FMP7://192.168.50.10/LHP Articles.fp7"
end if
end tell
--make sure document 1 exists
tell application "QuarkXPress"
if not (exists document 1) then
display dialog "You must have a Quark document open"
return
end if
end tell
tell application "FileMaker Pro Advanced"
tell database "LHP Database"
show
set article1 to cell "LINEITEMS_COMINGIN::article1" of current record
set article2 to cell "LINEITEMS_COMINGIN::article2" of current record
set article3 to cell "LINEITEMS_COMINGIN::article3" of current record
set article4 to cell "LINEITEMS_COMINGIN::article4" of current record
set article5 to cell "LINEITEMS_COMINGIN::article5" of current record
set article6 to cell "LINEITEMS_COMINGIN::article6" of current record
set article7 to cell "LINEITEMS_COMINGIN::article7" of current record
set article8 to cell "LINEITEMS_COMINGIN::article8" of current record
end tell
end tell
---SEARCH FOR ARTICLE ONE ---
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
show
do script "showAllRecords"
try
tell (every record whose (cell "article_number" = article1))
set article1Name to cell "article_name"
set article1Body to cell "article_body"
try
set graphicPath1 to cell "filePath"
end try
end tell
on error e
display dialog e
end try
end tell
end tell
---SEARCH FOR ARTICLE TWO ---
if article2 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
show every record
tell (every record whose (cell "article_number" = article2))
set article2Name to cell "article_name"
set article2Body to cell "article_body"
try
set graphicPath2 to cell "filePath"
end try
end tell
end tell
end tell
end if
---SEARCH FOR ARTICLE THREE ---
if article2 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
show every record
try
tell (every record whose (cell "article_number" = article3))
set article3Name to cell "article_name"
set article3Body to cell "article_body"
try
set graphicPath3 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
---SEARCH FOR ARTICLE FOUR ---
if article4 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
try
tell (every record whose (cell "article_number" = article4))
set article4Name to cell "article_name"
set article4Body to cell "article_body"
try
set graphicPath4 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
---SEARCH FOR ARTICLE FIVE ---
if article5 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
try
tell (every record whose (cell "article_number" = article5))
set article5Name to cell "article_name"
set article5Body to cell "article_body"
try
set graphicPath5 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
---SEARCH FOR ARTICLE SIX ---
if article6 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
try
tell (every record whose (cell "article_number" = article6))
set article6Name to cell "article_name"
set article6Body to cell "article_body"
try
set graphicPath6 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
---SEARCH FOR ARTICLE SEVEN ---
if article7 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
try
tell (every record whose (cell "article_number" = article7))
set article7Name to cell "article_name"
set article7Body to cell "article_body"
try
set graphicPath7 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
---SEARCH FOR ARTICLE EIGHT ---
if article8 ≠"" then
tell application "FileMaker Pro Advanced"
tell database "LHP Articles"
try
tell (every record whose (cell "article_number" = article8))
set article8Name to cell "article_name"
set article8Body to cell "article_body"
try
set graphicPath8 to cell "filePath"
end try
end tell
end try
end tell
end tell
end if
tell application "QuarkXPress"
activate
--- CREATE TEXT BOX POSITION 1 ---
tell page 2 of document 1
set ArticleOne to make text box at beginning of layer layerNumber with properties {name:"Text1", bounds:articleBoxFront1, runaround:none runaround}
tell ArticleOne
try
set story 1 to article1Name & return & article1Body
--Article Title and Body
set size of story 1 of ArticleOne to 11
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
--Article Title
tell paragraph 1 of story 1 of ArticleOne
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
end try
end tell
end tell
--CREATE FIRST PICTURE BOX
try
if graphicPath1 ≠"" then
tell page 2 of document 1
set pictBox1 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox1Front, color:"None"}
set box1 to get uniqueID of pictBox1
tell picture box 1
try
set image 1 to alias graphicPath1
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox1 to true
my updateRunaround()
set selected of pictBox1 to false
end tell
end if
end try
my fitBoxToText(ArticleOne)
tell application "QuarkXPress"
tell document 1
set j to text box "Text1"
set the horizontal measure to points
set the vertical measure to points
copy (bounds of j as list) to {tp, lft, bot, rt}
set newBottom to bot
end tell
end tell
set z to bot as real
set newBot to z + 15
copy articleBoxFront2 as list to {tpOld, lftOld, botOld, rtOld}
set newBounds to {newBot, lftOld, botOld, rtOld}
--- CREATE TEXT BOX POSITION 2 ---
if article2 ≠"" then
tell page 2 of document 1
set ArticleTwo to make text box at beginning of layer layerNumber with properties {name:"Text2", bounds:newBounds}
tell ArticleTwo
try
set story 1 to article2Name & return & article2Body
set size of story 1 of ArticleTwo to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleTwo
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
end try
end tell
end tell
end if
--CREATE SECOND PICTURE BOX
if graphicPath2 ≠"" then
tell page 2 of document 1
set pictBox2 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox2Front, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath2
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox2 to true
my updateRunaround()
set selected of pictBox2 to false
end tell
end if
my fitBoxToText(ArticleTwo)
tell application "QuarkXPress"
tell document 1
set j to text box "Text2"
set the horizontal measure to points
set the vertical measure to points
copy (bounds of j as list) to {tp, lft, bot, rt}
set newBottom to bot
end tell
end tell
set z to bot as real
set newBot to z + 15
copy articleBoxFront3 as list to {tpOld, lftOld, botOld, rtOld}
set newBounds to {newBot, lftOld, botOld, rtOld}
--- CREATE TEXT BOX POSITION 3 ---
if article3 ≠"" then
tell page 2 of document 1
set ArticleThree to make text box at beginning of layer layerNumber with properties {name:"Text3", bounds:newBounds}
tell ArticleThree
try
set story 1 to article3Name & return & article3Body
set size of story 1 of ArticleThree to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleThree
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE THIRD PICTURE BOX
if graphicPath3 ≠"" then
tell page 2 of document 1
set pictBox3 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox3Front, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath3
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox3 to true
my updateRunaround()
set selected of pictBox3 to false
end tell
end if
my fitBoxToText(ArticleThree)
--- CREATE TEXT BOX POSITION 4 ---
if article4 = "" then
return
else
tell page 1 of document 1
set ArticleFour to make text box at beginning of layer layerNumber with properties {name:"Text4", bounds:articleBoxBack1}
tell ArticleFour
try
set story 1 to article4Name & return & article4Body
set size of story 1 of ArticleFour to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleFour
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE FOURTH PICTURE BOX
try
if graphicPath4 ≠"" then
tell page 1 of document 1
set pictBox4 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox1Back, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath4
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox4 to true
my updateRunaround()
set selected of pictBox4 to false
end tell
end if
end try
my fitBoxToText(ArticleFour)
tell application "QuarkXPress"
tell document 1
set j to text box "Text4"
set the horizontal measure to points
set the vertical measure to points
copy (bounds of j as list) to {tp, lft, bot, rt}
set newBottom to bot
end tell
end tell
set z to bot as real
set newBot to z + 15
copy articleBoxBack2 as list to {tpOld, lftOld, botOld, rtOld}
set newBounds to {newBot, lftOld, botOld, rtOld}
--- CREATE TEXT BOX POSITION 5 ---
if article3 ≠"" then
tell page 1 of document 1
set ArticleFive to make text box at beginning of layer layerNumber with properties {name:"Text5", bounds:newBounds}
tell ArticleFive
try
set story 1 to article5Name & return & article5Body
set size of story 1 of ArticleFive to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleFive
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE FIFTH PICTURE BOX
if graphicPath5 ≠"" then
tell page 1 of document 1
set pictBox5 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox3Back, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath5
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox5 to true
my updateRunaround()
set selected of pictBox5 to false
end tell
end if
my fitBoxToText(ArticleFive)
tell application "QuarkXPress"
tell document 1
set j to text box "Text5"
set the horizontal measure to points
set the vertical measure to points
copy (bounds of j as list) to {tp, lft, bot, rt}
set newBottom to bot
end tell
end tell
set z to bot as real
set newBot to z + 15
copy articleBoxBack3 as list to {tpOld, lftOld, botOld, rtOld}
set newBounds to {newBot, lftOld, botOld, rtOld}
--- CREATE TEXT BOX POSITION 6 ---
if article6 ≠"" then
tell page 1 of document 1
set ArticleSix to make text box at beginning of layer layerNumber with properties {name:"Text6", bounds:newBounds}
tell ArticleSix
try
set story 1 to article6Name & return & article6Body
set size of story 1 of ArticleSix to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleSix
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE SIXTH PICTURE BOX
if graphicPath6 ≠"" then
tell page 1 of document 1
set pictBox6 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox4Back, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath6
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox6 to true
my updateRunaround()
set selected of pictBox6 to false
end tell
end if
my fitBoxToText(ArticleSix)
--- CREATE TEXT BOX POSITION 7 ---
if article7 ≠"" then
tell page 1 of document 1
set ArticleSeven to make text box at beginning of layer layerNumber with properties {name:"Text7", bounds:articleBoxBack4}
tell ArticleSeven
try
set story 1 to article7Name & return & article7Body
set size of story 1 of ArticleSeven to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleSeven
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE SEVENTH PICTURE BOX
if graphicPath7 ≠"" then
tell page 1 of document 1
set pictBox7 to make picture box at beginning of layer layerNumber with properties ¬
{bounds:pictureBox2Back, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath7
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
try
set properties of picture box 1 to {runaround:auto runaround, text outset:"12 pt"}
end try
set selected of pictBox7 to true
my updateRunaround()
set selected of pictBox7 to false
end tell
end if
my fitBoxToText(ArticleSeven)
tell application "QuarkXPress"
tell document 1
set j to text box "Text7"
set the horizontal measure to points
set the vertical measure to points
copy (bounds of j as list) to {tp, lft, bot, rt}
set newBottom to bot
end tell
end tell
set z to bot as real
set newBot to z + 15
copy articleBoxBack5 as list to {tpOld, lftOld, botOld, rtOld}
set newBounds to {newBot, lftOld, botOld, rtOld}
--- CREATE TEXT BOX POSITION 8 ---
if article8 ≠"" then
tell page 1 of document 1
set ArticleEight to make text box at beginning of layer layerNumber with properties {name:"Text8", bounds:newBounds}
tell ArticleEight
try
set story 1 to article8Name & return & article8Body
set size of story 1 of ArticleEight to 11
--set leading of every paragraph of story 1 to 12
set justification of every paragraph of story 1 to full
set font of story 1 to "Palatino"
tell paragraph 1 of story 1 of ArticleEight
set size of paragraph 1 to 19
set leading of paragraph 1 to 22
set style of every word to bold
set justification of paragraph 1 to centered
end tell
on error
display dialog "Text not found"
return
end try
end tell
end tell
end if
--CREATE EIGHTH PICTURE BOX
tell page 1 of document 1
make picture box at beginning with properties ¬
{bounds:pictureBox2Back, color:"None"}
tell picture box 1
--set rotation to -25
try
set image 1 to alias graphicPath7
set bounds of image 1 to proportional fit
set bounds of image 1 to centered
end try
end tell
end tell
end tell
on updateRunaround()
activate application "QuarkXPress"
tell application "System Events"
tell process "QuarkXPress"
click menu item "Runaround..." of menu 1 of menu bar item "Item" of menu bar 1
end tell
delay 1
keystroke (ASCII character (13))
end tell
end updateRunaround
on fitBoxToText(theTextbox)
tell application "QuarkXPress"
tell document 1
set {oldhm, oldvm} to {horizontal measure, vertical measure}
set {horizontal measure, vertical measure} to {points, points}
set theBaseline to (coerce baseline of character -1 of story 1 as vertical measurement to real)
set theDescent to (coerce descent of story 1 as font units to real)
set theTextbox to text box 1 of story 1
set theInset to text inset of theTextbox
if class of theInset is points rectangle then
set theInset to coerce (theInset as points rectangle) to list
set topInset to (coerce item 1 of theInset to real)
set botInset to (coerce item 3 of theInset to real)
else
copy (coerce theInset as inset units to real) to theInset
set topInset to theInset
set botInset to theInset
end if
copy (coerce top of bounds of theTextbox as vertical measurement to real) to theTop
set botcoord to (theBaseline + theTop + theDescent + topInset + botInset)
set bottom of bounds of theTextbox to botcoord
set {horizontal measure, vertical measure} to {oldhm, oldvm}
end tell
end tell
end fitBoxToText