●データベース出版(Professional DTPの特集記事から (PDF版-Acrobat3.0Jが必要です))
●ファイルメーカー Proのスクリプティング (PDF版-Acrobat3.0Jが必要です)
ファイルメーカー Pro(以下ファイルメーカー)は,v2.0からスクリプト対応しています。最新のv3.0をインストールすると,Apple Events リファレンスフォルダが作成され,その中に「Apple Events リファレンス」というデータベースが用意されています。これを開くと,スクリプティングに関して詳しい記述がなされています。サンプルスクリプトも書かれていますので,参考になると思います(執筆時点ではファイルメーカーv3.0のサブバージョンは3になっていますが,スクリプティングには違いはありません)。
●ファイルメーカーのオブジェクト
ファイルメーカーもQuarkXPressと同様,オブジェクトがあり,それが階層構造をしています。これについても,レファレンスに,わかりやすい記述がありますので参照してみてください。
サンプルのデータベースを作りましたので,これを利用してファイルメーカーとQuarkXPressを連携させていきたいと思います。
●サンプルのデータベース
図のようなデータベースを作成しました。データベースはオブジェクトDocument,レイアウトがオブジェクトLayout,カード1枚がオブジェクトRecord,カードに設定されたフィールド1つ1つがオブジェクトCellとなります。その他,FieldやDatabase等のオブジェクトがあります。
QuarkXPressでファイルメーカーのデータベースを利用するには,Layoutを指定して,各Recordから,必要なCellの内容をgetすることになります。そして,QuarkXPress側で,それをテキストボックスに流し込むことになります。
●フィールドの値を取得するスクリプト
tell application "ファイルメーカー Pro"
activate
tell document 1
tell layout 1
set CNTREC to count of record
repeat with J from 1 to CNTREC
tell record J
set CELLDATA to every cell
end tell
end repeat
end tell
end tell
end tell
これを実行すると,最初のカードのデータとして,変数CELLDATAには{"190", "立川市砂川町", "Gハウス上水", "鎌田幸雄", "0120-34-5678", "0120-34-5678", "0001", ヌdata EPSネ, "yukio.eps", ""}が設定されます。これを全レコード繰り返すことで,全データを取得できます。変数CELLDATAから,必要な項目を取り出し,QuarkXPressで設定すれば完了というのが基本的な処理になります。
●ファイルメーカーのスクリプトの限界
上記のスクリプトで,データの取得は可能です。しかし,多少不足していることがあります。
(1)文字属性
ファイルメーカーのフィールドは文字属性の定義が可能です。しかし,スクリプトにはそのプロパティが用意されていません。そのため,ファイルメーカーで定義した文字属性をそのままQuarkXPress側に反映させることは,この2つのアプリケーションだけでは自動的に行うことができません。後述する方法か,事前にQuarkXPress側でテキストボックスの文字属性を定義しておく必要があります。
(2)画像
先の変数CELLDATAの中に,ヌdata EPSネとなっているのが画像の部分です。実際はヌdata
EPS 252150532D41646652D...(略)ネとプレビュー画像のバイナリデータが取得できるだけです。
●対策
上記のような限界を考慮する必要があります。しかし,次のような対策をとれば問題点も解決します。
(1)文字属性についてはスクリプタブルなエディタを利用すれば,対応可能になります。つまり,ファイルメーカーのフィールドの文字をコピーして,スクリプタブルなエディタにペーストします。そこで,フォント名・サイズ・文字飾りのプロパティを取得して,QuarkXPress側に反映するという方法です。
(2)画像については,画像名称をフィールドに入力しておきます。画像のあるフォルダをあらかじめ指定して,その中から画像名称を検索して,QuarkXPress側に反映するという方法です。
●QuarkXPressでのスクリプティング
このデータベースの内容を,どのようなドキュメントに反映するのかによって,QuarkXPress側のスクリプトが変わってきます。今回は,次のようなドキュメントを想定してみましょう。
Aハガキの宛名
B写真付の名刺
C住所録
●ハガキの宛名
ハガキの大きさのドキュメントを作成し,そのマスターページに,テキストボックスを文字属性も含めて定義しておきます。そして,各テキストボックスのインデックスが何番かを確認しておきます。
データベースから取得したテキストを何番のテキストボックスに流し込むかを決めるだけで,あとは,各データごとにその繰り返しとなります。
データベースとテキストボックスが1対1の対応していますので,スクリプトも簡単なものとなります。
set CELLDATA to {}
tell application "ファイルメーカー Pro"
activate
tell document 1
tell layout 1
set CNTREC to count of record
repeat with J from 1 to CNTREC
tell record J
beep
set CELLDATA to CELLDATA & {cells 1 thru 4}
end tell
end repeat
end tell
end tell
end tell
--
tell application "QuarkXPress3.3J"
activate
tell document 1
repeat with J from 1 to CNTREC
tell page J
if J is not 1 then set master spread to spread 1 of master
document 1 --*1
show
set story 1 of text box 1 to item 1 of item J of CELLDATA
--*2
set story 1 of text box 2 to item 2 of item J of CELLDATA
set story 1 of text box 3 to item 3 of item J of CELLDATA
set story 1 of text box 4 to item 4 of (item J of CELLDATA)
& " 様"
end tell
if J is not CNTREC then make spread at end
end repeat
end tell
end tell
*1:新規ページにマスターページを適用する
*2:4つのテキストボックスにデータベースから取得した値を設定する
実行結果
●写真付の名刺
ハガキと異なることは,複数データを1ページに割り付けることです。テキストボックスのインデックスを事前に調べておいて,テキストボックスに名前を付ける処理を行っています。
set CELLDATA to {}
choose folder with prompt "画像の入ったフォルダを選択してください"
set THEPATH to result
tell application "ファイルメーカー Pro"
activate
tell document 1
tell layout 1
set CNTREC to count of record
repeat with J from 1 to CNTREC
tell record J
beep
set CELLDATA to CELLDATA & {cells 1 thru 6 &
cell 9}
end tell
end repeat
end tell
end tell
end tell
tell application "QuarkXPress3.3J"
activate
tell document 1
repeat with J from 1 to 2
tell page J
show
if J is not 1 then set master spread to spread 1 of master
document 1
my NAMINGBOX()
repeat with K from 1 to 4
tell picture box (5 - K) --*1
try
set image 1 to THEPATH & item 7 of item
K of CELLDATA as text
set bounds of image 1 to proportional fit
on error
end try
end tell
tell (text boxes whose name begins with (K as text)
and name contains "氏名") --*2
set IDX to index
set STRY to item 4 of item K of CELLDATA as text
my SETTEXT(IDX, STRY)
end tell
tell (text boxes whose name begins with (K as text)
and name contains "住所")
set YUBIN to item 1 of item K of CELLDATA as text
set JYU1 to item 2 of item K of CELLDATA as text
set JYU2 to item 3 of item K of CELLDATA as text
set IDX to index
set STRY to YUBIN & " " & JYU1
& " " & JYU2
my SETTEXT(IDX, STRY)
end tell
tell (text boxes whose name begins with (K as text)
and name contains "Tel")
set IDX to index
set STRY to item 5 of item K of CELLDATA as text
my SETTEXT(IDX, STRY)
end tell
tell (text boxes whose name begins with (K as text)
and name contains "Fax")
set IDX to index
set STRY to item 6 of item K of CELLDATA as text
my SETTEXT(IDX, STRY)
end tell
end repeat
try
set CELLDATA to items 5 thru -1 of CELLDATA
on error
end try
end tell
if J is not CNTREC then make spread at end
end repeat
end tell
end tell
--サブルーチン
on SETTEXT(IDX, STRY) --*3
tell application "QuarkXPress3.3J"
tell document 1
tell current page
tell text box IDX
set story 1 to STRY
end tell
end tell
end tell
end tell
end SETTEXT
--
on NAMINGBOX() --*4
tell application "QuarkXPress3.3J"
tell document 1
tell current page
set name of picture box 1 to "4-画像"
set name of text box 1 to "4-住所"
set name of text box 2 to "4-Fax"
set name of text box 3 to "4-Tel"
set name of text box 4 to "4-氏名"
set name of picture box 2 to "3-画像"
set name of text box 9 to "3-住所"
set name of text box 10 to "3-Fax"
set name of text box 11 to "3-Tel"
set name of text box 12 to "3-氏名"
set name of picture box 3 to "2-画像"
set name of text box 17 to "2-住所"
set name of text box 18 to "2-Fax"
set name of text box 19 to "2-Tel"
set name of text box 20 to "2-氏名"
set name of picture box 4 to "1-画像"
set name of text box 25 to "1-住所"
set name of text box 26 to "1-Fax"
set name of text box 27 to "1-Tel"
set name of text box 28 to "1-氏名"
end tell
end tell
end tell
end NAMINGBOX
*1:事前に調べたテキストボックスに名前を付ける。repeat文で利用できるよう,先頭1文字に数字を指定する
*2:tell (text boxes whose name begins with (K as text) and name contains
"氏名") という方法でテキストボックスを指定する
*3:しかし,画像ボックスには上記の方法が有効ではない(何故だ!)
*4:メインルーチンでテキストボックスのインデックスを取得し,ここでテキストボックスを指定して,storyにテキストを流し込む。インデックスを取得しないで,メインルーチンでset
story 1 to STRYを指定したいのだが,動作する時としない時がある。不安定のため,この方法をとった。
実行結果
●住所録
データベースから取得したテキストを1行に編集します。そして,段落内の電話番号とファックス番号の書体・級数を変更します。
set CELLDATA to {}
tell application "ファイルメーカー Pro"
activate
tell document 1
tell layout 1
set CNTREC to count of record
repeat with J from 1 to CNTREC
tell record J
beep
set CELLDATA to CELLDATA &{cells 1 thru 7 &cell 10}
end tell
end repeat
end tell
end tell
end tell
tell application "QuarkXPress3.3J"
activate
tell document 1
tell current page --*1
show
repeat with J from 1 to CNTREC
set BANGOU to item 7 of item J of CELLDATA
set NAMAE to item 4 of item J of CELLDATA
set YUBIN to item 1 of item J of CELLDATA
set JYU1 to item 2 of item J of CELLDATA
set JYU2 to item 3 of item J of CELLDATA
set JYUSHO to JYU1 &" " &JYU2
set DENWA to item 5 of item J of CELLDATA
set FAX to item 6 of item J of CELLDATA
set BIKO to item 8 of item J of CELLDATA
set LINEDATA to BANGOU &tab &NAMAE &tab &YUBIN &tab
&JYUSHO &tab &DENWA &tab &FAX &tab &BIKO --*2
tell text box 3
make line at end
set line J to LINEDATA &return --*3
my CNTBYTE(BANGOU &tab &NAMAE &tab &YUBIN &tab
&JYUSHO &tab)
set STBYTE to result
my CNTBYTE(BANGOU &tab &NAMAE &tab &YUBIN &tab
&JYUSHO &tab &DENWA &tab &FAX)
set ENDBYTE to result --*4
tell characters (STBYTE + 1) thru ENDBYTE of paragraph
J
set font to "中ゴシック体"
set size to "7 pt"
end tell
end tell
end repeat
end tell
end tell
end tell
--
on CNTBYTE(CNTTXT) --*5
set THEPATH to (path to me)
open for access THEPATH with write permission
set THEEOF to (get eof THEPATH)
write CNTTXT to THEPATH starting at THEEOF
set NWEOF to (get eof THEPATH)
set NUMBYTE to NWEOF - THEEOF
set eof THEPATH to THEEOF
close access THEPATH
return NWEOF
end CNTBYTE
*1:新規ページの追加の処理は考慮していません
*2:一行にデータを再設定する
*3:文字数をバイト数で数えたいため,カウント対象文字列をサブルーチンに渡す
*4:電話番号とファックス番号の書体・級数を変更する
*5:文字数をバイト数で数えるサブルーチン
実行結果