从所选文本生成脚注

时间:2011-02-08 14:45:03

标签: adobe-indesign extendscript

我正在尝试使用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
}

1 个答案:

答案 0 :(得分: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 = "";
}