12月 6, 2010
kamata

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

  • サブルーチンにして、アプリケーション直下で処理するとできるようです。
    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の下だったのですね。

Leave a comment to Kamata