gpt4 book ai didi

javascript - InDesign 中的文本转脚注

转载 作者:太空宇宙 更新时间:2023-11-04 10:27:57 24 4
gpt4 key购买 nike

我正在尝试运行一个脚本,该脚本有助于自动转换文本并将其放置到 InDesign 文档中的脚注中。脚本:

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();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------

每当我尝试在包含以下样式和文本的文档中运行此脚本时:Text

它会生成以下错误: Error

有人可以帮助我了解脚本到底出了什么问题吗?我在多个文件中都遇到过这一问题,并且对脚本编写一无所知。

任何帮助将不胜感激。问候,阿曼·米塔尔

最佳答案

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

关于javascript - InDesign 中的文本转脚注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50325958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com