Reply To: Convert Footnotes and Endnotes bug + bonus scripting bug

Home Page / Forums / General InDesign Topics (CLOSED) / Convert Footnotes and Endnotes bug + bonus scripting bug / Reply To: Convert Footnotes and Endnotes bug + bonus scripting bug

#14364995

For anyone interested the script below will insert footnote numbers back into all footnotes.


var scriptName = File($.fileName).name;
app.scriptPreferences.enableRedraw = false; //Does not seem to work in this case

Application.prototype.main = function() {
var theDoc = app.activeDocument;
var theStory;
try{
theStory = app.selection[0].parentStory;
}
catch(e)
{
alert("Place cursor i story with footnotes and try again");
exit();
}
var theFootnotes = theStory.footnotes.everyItem().getElements();
var theCounter = 0;

//progressbar setup
var w = new Window('palette', 'Inserting footnote numbers ...', {x:200, y:200, width:350, height:70});
w.pbar = w.add('progressbar', {x:25, y:12, width:300, height:12}, 0, theFootnotes.length);
w.st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');
w.st.justify = 'center';
w.show();

//new temporary footnote
var tempNote = theStory.insertionPoints[-1].footnotes.add();

//Select and copy text from the temp footnote
var theFootnoteNumber = tempNote.texts[0]; //includes both the number and the following tab character
app.select(theFootnoteNumber);
app.copy();

// remove temp footnote
tempNote.remove();

//iterate existing footnotes and insert footnotenumber
for (var i = theFootnotes.length-1; i >= 0 ; i--) {
app.select(theFootnotes[i].paragraphs[0].insertionPoints[0]);
app.paste();
theCounter++;
w.pbar.value = theFootnotes.length-i;
w.st.text = "Processing item " + w.pbar.value + " of " + theFootnotes.length + " total";
}
alert("Inserted footnote number in " + theCounter + " footnotes.");
}
app.doScript('app.main();',ScriptLanguage.JAVASCRIPT,undefined,UndoModes.ENTIRE_SCRIPT,scriptName);

This article was last modified on April 29, 2022

Comments (0)

Loading comments...