简体   繁体   English

InDesign 中的文本到脚注

[英]Text to Footnote in InDesign

I am trying run a script that helps in automatically converting and placing text to footnotes in an InDesign document.我正在尝试运行一个脚本,该脚本有助于在 InDesign 文档中自动转换和放置文本到脚注。 Script:脚本:

 var scriptName = "Convert text to footnote", doc, story; app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\\"" + scriptName + "\\" script"); //===================================== FUNCTIONS ====================================== function Main() { var mEndNotes = doc.textFrames.add( {name:"EndNotes"} ), k, len, cIP, currPara, currFoot, mMarkers; app.findGrepPreferences = app.changeGrepPreferences = null; //--------------------------------------------- // edit doc.footnoteOption here with (doc.footnoteOptions) { showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH; prefix = "["; suffix = "]"; separatorText = "\\t"; markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER; } //------------------------------------------------------------ // move endnotes to a separate textFrame for (k=story.paragraphs.length - 1; k >=0; k--) { if (story.paragraphs[k].contents.search(/^\\[\\d+\\]/) == 0) { currPara = story.paragraphs[k].move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory); currPara.words[0].remove(); } } //-------------------------------------- // create footnote markers app.findGrepPreferences.findWhat = "\\\\[\\\\d+\\\\]"; mMarkers = story.findGrep(); len = mMarkers.length; while (len-->0) { cIP = mMarkers[len].insertionPoints[0].index; mMarkers[len].remove(); story.footnotes.add( LocationOptions.AFTER, story.insertionPoints[cIP] ); } //------------------------------------------------------- // fill footnote contents with proper text for (k=0; k < story.footnotes.length; k++) { currFoot = story.footnotes[k]; mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]); if (story.footnotes[k].characters[-1].contents == "\\r") story.footnotes[k].characters[-1].remove(); } mEndNotes.remove(); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function PreCheck() { if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true); doc = app.activeDocument; if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true); if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true); if (app.selection.length == 0) { ErrorExit("Nothing is selected.", true); } else if (app.selection.length == 1) { if (app.selection[0].constructor.name == "TextFrame" || app.selection[0].hasOwnProperty("baseline")) { story = app.selection[0].parentStory; } else { ErrorExit("Please select one text frame, or some text, or place the cursor and try again.", true); } } else if (app.selection.length > 1) { ErrorExit("Only one text frame or some text should be selected, or the cursor placed into the text.", true); } Main(); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ErrorExit(error, icon) { alert(error, scriptName, icon); exit(); } //--------------------------------------------------------------------------------------------------------------------------------------------------------

Whenever I try to run this script in a document containing the following styling and text: Text每当我尝试在包含以下样式和文本的文档中运行此脚本时:文本

It generates the following error: Error它生成以下错误:错误

Could anyone help me with the idea of actually what is going wrong with the script?任何人都可以帮助我了解脚本实际上出了什么问题吗? I have faced this problem in more than one file and have no idea about scripting.我在多个文件中遇到过这个问题,并且对脚本一无所知。

Any help would be much appreciated.任何帮助将非常感激。 Regards, Aman mittal问候, 阿曼·米塔尔

在执行脚本之前,请检查安装的 indesign 版本和 indesign 文件应该打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM