LoginSignup
1
0

More than 1 year has passed since last update.

InDesign JavaScript ライブキャプションの作成

Posted at

ライブキャプションの作成をするスクリプトは、これで良いのかな・・・?

/*
このスクリプトを利用して起こった不具合の責任は取れません。
ご了承下さい。

更新 2021/11/08
*/

// アプリ指定
#target "indesign";

// スクリプト名
var scriptName = "ライブキャプションの作成";

//スクリプトの動作指定(一つのアンドゥ履歴にする、及び、アンドゥ名)
app.doScript(function(){

    // 検索の初期化
    app.findTextPreferences = NothingEnum.NOTHING;

        // ダイアログ
    var dialogueFlg = confirm("全ての画像に「オブジェクト」メニューの「キャプション」の「ライブキャプションの作成」を行います。" + "\r"
    + "ライブキャプションの作成が行えない画像には作成は行われません。" + "\r\r"
    + "処理で画像(Rectangle)を選択します。" + "\r"
    + "処理に時間がかかる場合は「ページ」や「索引」、スタイルのウィンドウ等は閉じておいた方が良いかもしれません。" + "\r"
    + "「検索と置換」ウィンドウの 『テキスト』の検索文字列に進行状況を表示します。" + "\r"
    + "止まっているのか動いているのかの判断が出来ると思います(スクリプトウィンドウのメニューの「再描画を有効にする」が選択されている場合)。"
    ,"", scriptName);

    // Noの場合
    if (dialogueFlg == false) {

        // 終了
        exit();
    }

    var textVariablesAssociatedInstancesCount = 0;
    var originTextVariablesAssociatedInstancesCount = countTextVariablesAssociatedInstances(app.activeDocument.textVariables);

    var repeatCount = 0;

    for(var i = 0; i < app.activeDocument.allGraphics.length; i++){

        if(app.activeDocument.allGraphics[i].parent.constructor.name == "Rectangle"){

            app.activeDocument.allGraphics[i].parent.select();

            // 処理中表示用
            app.findTextPreferences.findWhat = "processing selectObjectID:" + app.activeDocument.selection[0].id;

            if(app.menuActions.itemByID(132644).enabled){

                app.menuActions.itemByID(132644).invoke();
            }
        }
    }

    // 検索の初期化
    app.findTextPreferences = NothingEnum.NOTHING;

    textVariablesAssociatedInstancesCount = countTextVariablesAssociatedInstances(app.activeDocument.textVariables) - originTextVariablesAssociatedInstancesCount;

    // 結果
    alert("ライブキャプション追加数 " + textVariablesAssociatedInstancesCount);

//スクリプトの動作指定の続き
}, ScriptLanguage.JAVASCRIPT, [scriptName], UndoModes.ENTIRE_SCRIPT, scriptName);

function countTextVariablesAssociatedInstances(textVariableCollection){

    // 初期化
    textVariablesAssociatedInstancesCount = 0;

    for(var i = 0; i < textVariableCollection.count(); i++){

        textVariablesAssociatedInstancesCount += textVariableCollection.item(i).associatedInstances.length;
    }

    return textVariablesAssociatedInstancesCount;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0