Illustrator script : フォントの検索置換
Illustrator8で作られた大量のepsファイルを開き、otfフォント置換する必要が生じた。
最初AppleScriptで作ってみたが、属性text fontはRead Only だと言われ置換できず。
ググると、JavaScriptでできるようだ(でも自分はJSは書けない)。
なので、JavaScript部は拝借して、こうしてみた。
—————————————————————————————————
set myJavascript to “ function repFont(font1, font2){ selObj = app.activeDocument.textFrames; for (var i=0; i< selObj.length; i++){ selText = selObj[i].textRange.characters; for (var j=0; j< selText.length; j++){ var tFont = selText[j].characterAttributes.textFont; if (tFont == font1) { selText[j].characterAttributes.textFont = font2; }}}} fnt1 = app.textFonts.getByName(arguments[0]); fnt2 = app.textFonts.getByName(arguments[1]); repFont(fnt1, fnt2);” tell application “Adobe Illustrator” set findFont to “ShinGo-regular” set repFont to “ShinGoPro-Light” do javascript myJavascript with arguments {findFont, repFont} end tell(wrriten by Kamata)
2 Comments
Leave a comment
記事投稿日
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
« 9月 | ||||||
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
サブルーチンにして、アプリケーション直下で処理するとできるようです。
Illustratorのオブジェクト構造を見ると、text fontはアプリケーション直下のオブジェクトになっています。これは分かりづらいですねぇ。
tell application “Adobe Illustrator”
tell document 1
set txtObj to text frame 1
set fontName to “KozMinPro-Regular”
changeFont(txtObj, fontName) of me
end tell
end tell
on changeFont(txtObj, fontName)
tell application “Adobe Illustrator”
set properties of every character of every text of txtObj to {text font:text font fontName}
end tell
end changeFont
inomotoさん、ありがとう。
appの下だったのですね。