2011-02-08 13 views
1

私はExtendScriptを使用してInDesignのスクリプトを作成しようとしています。スクリプトで選択したテキストを切り取り、脚注を挿入してテキストを脚注の本文に貼り付けるようにします。私が試してみました:選択したテキストから脚注を生成

function makeFootnoteOfSelection(){ 
    var fnText = app.activeDocument.selection[0]; 
     // this should actually clone the selected text, not reference it, because the next statement zaps it from memory 
    app.activeDocument.selection[0].remove(); // works 
    var fNote = app.activeDocument.selection[0].footnotes.add(); // works, adds an empty footnote with a reference 
    fNote.contents = fnText.contents; 
     // this replaces the reference number, I was hoping to retain it and just add the text 
     // fNote.contents += fnText.contents; also replaces the reference number 
} 

答えて

5

のInDesign CS5:

function makeFootnoteOfSelection(){ 

    // Reference the selection 
    var fnText = app.activeDocument.selection[0]; 

    // Add an empty footnote where the selected text is 
    var fNote = app.activeDocument.selection[0].footnotes.add(); 

    // Move the selected text at the end of the empty footnote 
    fnText.move(LocationOptions.AFTER, fNote.insertionPoints[-1]); 
} 

のInDesign CS4:

function makeFootnoteOfSelection(){ 

    // Reference the selection 
    var fnText = app.activeDocument.selection[0]; 

    // Position of the text end 
    var endPoint = fnText.length - 1; 

    // Add an empty footnote where the selected text is 
    var fNote = app.activeDocument.selection[0].footnotes.add(); 

    // Duplicate the selected text at the end of the empty footnote 
    fnText.duplicate(LocationOptions.AFTER, fNote.insertionPoints[-1]); 

    // Delete the old Text 
    fnText.characters.itemByRange(0, endPoint).contents = ""; 
} 
+0

スクリプトエラーアウトを "テキストが現在の場所に移動することはできません" と3番目のステップで。私はそれがステップ2の後の選択に脚注が含まれているからだと思います。 –

+0

InDesign CS4を使用していますか?それは私に同じエラーを与えました。しかし私は私のために働く別の解決策を見つけました。あなたの推測は正しいかもしれません。脚注は、私が想像する特定の挿入ポイントに結びついています。したがって、この点が選択範囲内にある場合、脚注も同様です。しかし、彼らはあなたが期待するようにCS5の動作を変更したようです。 – Jonas

+0

優秀!あなたは天才です。このことをどうやって学びましたか?オブジェクトモデルビューアから?サンプルスクリプトを勉強することによって?どうもありがとう。 –

関連する問題