Copy link to clipboard
Copied
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");
}
@m1b @Robert at ID-Tasker , hi all, thanks a lot for your help and suggestions, i create a new crazy method to fix this! and it works!, here it is :
//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 = fals
...
This seems to me simpler:
var myDoc = app.activeDocument,
myFootnotes = myDoc.stories.everyItem().footnotes.everyItem().getElements(),
F = myFootnotes.length, f;
//---------------------------
var myStart = 1, myEnd = 8;
//---------------------------
var myTxt = File("~/Desktop/Doc Exported Footnotes in Pages Range .txt");
myTxt.encoding = "UTF-8";
myTxt.open("w");
for ( var f = 0; f < F; f++ ) {
var myPage = myFootnotes[f].storyOffset.parentTextFrames[0].parentPage.name;
if ( myPage >=
...
Copy link to clipboard
Copied
Hi @M.Hasanin, so your exported text file shows the same contents and page name multiple times? Could you post a small sample .indd file for us to test with your script? - Mark
Copy link to clipboard
Copied
//First nested loop to grab all the found texts in Range of Paragraphs in Page Range
Why nested loops ?
var myFoundTextParagraphs = pageRange.findGrep();
This should return simple array - not array of arrays ?
myFoundTexts.push(myFoundTextParagraphs[i][j]);
??
This loop will return myFoundTextParagraphs.length² results ??
Copy link to clipboard
Copied
@Robert at ID-Tasker, the result of
myDoc.pages.itemByRange(pgStart, pgEnd).textFrames.everyItem().paragraphs.everyItem().findGrep();
is an array of arrays. It's because of the use of everyItem().
- Mark
Copy link to clipboard
Copied
Right 😞 missed "[i]" in the inside loop 😞
Copy link to clipboard
Copied
Why not go through all TextFrames on the range of pages and export their Footnotes?
But then you'll need to sort them by index - or findGrep returns them in the correct order? Or you don't need them organised?
Copy link to clipboard
Copied
i did it and it succeeded before for the all book , but the original complete book is near 180 pages and other book near 500 pages so i decide to make it in range!, and no need to sort them, i start thinking to import text file inside indesign and removing duplicates via grep or make a new script for that, thank for your suggestion
Copy link to clipboard
Copied
Thanks a lot for replying me, i found that some results are duplicated!, here is part of book, the link of 30 page of the book project , download from here (Google Drive) :
you can found it mixed language footnotes (Arabic and English) - GIF Animation
Copy link to clipboard
Copied
@m1b @Robert at ID-Tasker , hi all, thanks a lot for your help and suggestions, i create a new crazy method to fix this! and it works!, here it is :
//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 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");
//New Method for Pages Range!
for (var n = pgStart; n <= pgEnd; n++) {
var pageRange = myDoc.pages[n].textFrames.everyItem();
var myFoundTextParagraphs = pageRange.findGrep();
//First nested loop to grab all the found texts in Range of Paragraphs in Page Range
//is an array of arrays. It's because of use of everyItem().
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", "Finished");
}
Copy link to clipboard
Copied
@m1b I thought that each instance of everyItem() creates another dimension - in the new version there is only one - so why nested loops ??
@M.Hasanin you've misunderstood my idea 😞 I've suggested to just iterate through all TextFrames - and process their collections of Footnotes - not to search every TextFrame - so your code would be much simpler and quicker.
Copy link to clipboard
Copied
Thanks for your reply but can you please give me written code example for doing that ? or algorithm steps
Copy link to clipboard
Copied
Would prefer algorithm as JS isn't my forte 😉
1st loop - through pages,
2nd loop - nested - through TextFrames,
3rd loop - nested - through Footnotes.
Copy link to clipboard
Copied
@Robert at ID-Tasker Thank you, i will try to apply this algorithm and see what will happened
Copy link to clipboard
Copied
This seems to me simpler:
var myDoc = app.activeDocument,
myFootnotes = myDoc.stories.everyItem().footnotes.everyItem().getElements(),
F = myFootnotes.length, f;
//---------------------------
var myStart = 1, myEnd = 8;
//---------------------------
var myTxt = File("~/Desktop/Doc Exported Footnotes in Pages Range .txt");
myTxt.encoding = "UTF-8";
myTxt.open("w");
for ( var f = 0; f < F; f++ ) {
var myPage = myFootnotes[f].storyOffset.parentTextFrames[0].parentPage.name;
if ( myPage >= myStart && myPage <= myEnd ) myTxt.writeln(myFootnotes[f].contents + "\t" + myPage);
}
myTxt.close();
alert("Document Footnotes Exported to Desktop File", "Finished");
(^/) The Jedi
Copy link to clipboard
Copied
You have used everyItem() twice - but then you are referring to the items as in the single size array?
Copy link to clipboard
Copied
@Robert at ID-Tasker, the getElements() method of an everyItem() result returns a flat array of the resolved elements. In OP's case they did not use getElements(), because they wanted to use findGrep() method, which Array does not have.
Copy link to clipboard
Copied
Thanks.
Copy link to clipboard
Copied
@FRIdNGE genius method, yes it is much simpler Jedi!,Thanks a lot
Copy link to clipboard
Copied
Copy link to clipboard
Copied
myFootnotes is an array of all the footnotes in your document (it was made earlier in the script)
storyOffset gets the insertionPoint of the footnote
parentTextFrames[0] gets the textFrame that contains that insertionPoint
parentPage gets the page that contains the textFrame
name is the name of the page.
Copy link to clipboard
Copied
thanks for explaining, i know the last three lines, it just first time to concentrate with StoryOffset, not much examples around!, thanks for help, have a best day