Answered
Export Footnotes in Pages Range using Grep and Array Causing Exported Duplicates in text File!
hi Experts,
Im trying to export footnotes in pages range, it works and no errors but i found the exported (text) file contain duplicates of the results!, maybe something wrong in my logic but i cant catch the logical error!, please help and thanks in advance.
//Export Footnotes in Pages Range
DoFootnotesRange();
function DoFootnotesRange(){
//Array for the Collected Footnotes Text
var myFoundTexts = [];
//grep options
app.findChangeGrepOptions.includeMasterPages = false;
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = true;
app.findChangeGrepOptions.includeLockedStoriesForFind = true;
var myDoc = app.activeDocument;
var pgStart = 0;
var pgEnd = 9;
var pageRange = myDoc.pages.itemByRange(pgStart, pgEnd).textFrames.everyItem().paragraphs.everyItem();
var myFind = "~F.+$";
//Clear Grep Prefrences
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = myFind;
try {
var myDoc = app.activeDocument;
} catch(e) { exit(); }
var f = File("~/Desktop/Doc Exported Footnotes in Pages Range .txt");
f.encoding = "UTF-8";
f.open("w");
var myFoundTextParagraphs = pageRange.findGrep();
//First nested loop to grab all the found texts in Range of Paragraphs in Page Range
for (var i = 0; i < myFoundTextParagraphs.length; i++) {
for (var j = 0; j < myFoundTextParagraphs[i].length; j++) {
myFoundTexts.push(myFoundTextParagraphs[i][j]);
}
}
//Now Loop to Show Found Text in Array
for (var k = 0; k < myFoundTexts.length; k++) {
f.writeln (myFoundTexts[k].contents+"\t"+myFoundTexts[k].parentTextFrames[0].parentPage.name)
}
app.findGrepPreferences = app.changeGrepPreferences = null;
f.close();
alert("Document Footnotes Exported to Desktop File, "+myFoundTexts.length+" Footnotes Collected!", "Finished");
}
