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)
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)
| 归档时间: |
|
| 查看次数: |
1994 次 |
| 最近记录: |