2011-02-08 28 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

腳本錯誤了與 「文本不能移動到現在的位置」在第三步。我認爲這是因爲腳註包含在步驟2之後的選擇中。 – 2011-02-11 06:53:07