00)Illustratorをコントロールするの最近のブログ記事

EXCELの行をコピーしIllustratorの選択した小組に流し込みます。テキストフレームがエリアテキストの場合はオーバーフローすれば収まるように長体がかかります。改行を含む文字の場合の長体処理はしていません。
小組のテキストフレーム1つ1つにIllustratorのレイヤーパレットで"A","B","C","D"・・・と名前をあらかじめつけておきます。

ex-ai01.jpg

※レイヤーに名前を付けるようにレイヤーパレット内のテキストをダブルクリックして名前を付ける事が出来ます。

このテキストフレームがEXCELの列の"A","B","C","D"・・・と関連づきます。

ex-ai02.jpg

※EXCELのA列の文字がIllustratorの"A"と名前を付けたテキストフレームに流し込まれます。

準備が終わったらIllustratorの小組を選択し、EXCELの行をコピーしてからスクリプトを実行してみてください。

global textFlameList
set myRec to the clipboard
set textFlameList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

set OriginalDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {tab}
set myRec to text items of myRec

tell application "Adobe Illustrator"
	tell document 1
		set mySele to selection
		repeat with selObj in mySele
			my getTextFrameIndex(selObj)
		end repeat
		repeat with N from 1 to count myRec
			my NAGASIKOMI(item N of textFlameList, item N of myRec)
		end repeat
	end tell
end tell
set AppleScript's text item delimiters to OriginalDelimiters

on getTextFrameIndex(selObj)
	tell application "Adobe Illustrator"
		if class of selObj is group item then
			set myCount to count page items of selObj
			repeat with N from 1 to myCount
				my getTextFrameIndex(page item N of selObj)
			end repeat
		else if class of selObj is text frame then
			set myName to name of selObj
			set itemNum to my getItemNum(myName)
			if itemNum > 0 then
				set item itemNum of textFlameList to selObj
			end if
		end if
	end tell
end getTextFrameIndex

on getItemNum(myName)
	return offset of myName in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end getItemNum

on NAGASIKOMI(targetTextFrame, inputStr)
	if targetTextFrame is 0 then
		return
	end if
	tell application "Adobe Illustrator"
		set contents of targetTextFrame to inputStr
		if kind of targetTextFrame is area text then
			if my overflow(targetTextFrame) is true then
				set mySCL to horizontal scale of paragraph 1 of targetTextFrame
				my choutai(targetTextFrame, mySCL)
			end if
		end if
	end tell
end NAGASIKOMI

on choutai(targetTextFrame, mySCL)
	set mySCL to mySCL - 3
	tell application "Adobe Illustrator"
		set horizontal scale of paragraph 1 of targetTextFrame to mySCL
	end tell
	if my overflow(targetTextFrame) is true then
		my choutai(targetTextFrame, mySCL)
	end if
end choutai

on overflow(tFrame)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ""
	tell application "Adobe Illustrator"
		set myLastP to (contents of every paragraph of tFrame) as string
		set myLastL to (contents of every line of tFrame) as string
		set AppleScript's text item delimiters to OriginalDelimiters
		if myLastP is not myLastL then
			set AppleScript's text item delimiters to OriginalDelimiters
			return true
		else
			set AppleScript's text item delimiters to OriginalDelimiters
			return false
		end if
	end tell
end overflow

22)処理が止まってしまうとき

| コメント(0) | トラックバック(0)

ダイアログがでてAppleScriptの応答待ちで処理が止まってしまうときは、第2章のエラー処理などで紹介したtime outの設定をつかい1秒応答がなければIllustratorを落とす方法で逃げる。しかしその場合もAppleScriptからIllustratorにQuitコマンドを送っても応答しないのでshellから強制的に落とす。興味ある方は調べてみてください。

文字列の検索置換や段落・文字スタイルの適応(おそらくInDesignと同じ)タブの設定やシンボルの配置。さらに詳しく見ていくとグラデーションやブラシなどクラスはいっぱいあるので、AppleScriptでコントロールできるはず、だが省略。。。
したくてもできない事は

Illustratorでドキュメントを開くときリンクが見つからないとかエラーダイアログが出てしまうときがある。
ダイアログを出さずにオープンする事ができない。
お〜まちさんの指摘より下記でダイアログを出さずに開く事ができました。

tell application "Adobe Illustrator"
	open file "Macintosh HD:TEST10.ai" without dialogs
end tell

㎝など特殊な文字は流し込みに失敗する。
Unicodeはいけます。

レイヤー名やオブジェクト名に日本語を使うとAppleScriptで値を取り出すとき文字化けする。
CS2で解決している

アピアランスがコントロールできない。などなど。わたしの思い違いも多々あると思うのでおかしな点はご指摘ください。

エントリー一覧

OpenID対応しています OpenIDについて
Powered by Movable Type 7.902.0
漢字イラストロジック-脳トレ京
FREE ONLINE SUDOKU