从所选文本生成脚注

Jan*_*sen 1 extendscript adobe-indesign

我正在尝试使用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
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*nas 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]);
}
Run Code Online (Sandbox Code Playgroud)

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 = "";
}
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢\*脸红\*.在http://www.jongware.com/idjshelp.html上有一个更好的对象模型查看器版本,我广泛使用它.有时,通过InDesign处理事物(如脚注)是如何反复试验的.我几乎从不使用Adobes代码示例,因为我不喜欢他们的编程风格. (2认同)