-
1. Re: footnotes solution?
Kasyan Servetsky Sep 26, 2009 4:59 PM (in response to pretendermadafaka)Here is a very basic script I wrote for you to illustrate how this can be done. Run it against the attached file.
Kasyan
var myDoc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findGrepPreferences.findWhat = "\\>\\[\\d+\\]";
var arr1 = myDoc.findGrep(true);
app.findGrepPreferences.findWhat = "^\\[\\d\\].+";
var arr2 = myDoc.findGrep(true);
var arr2cont = GetContents(arr2);for (i = 0; i < arr1.length; i++) {
myFN = arr1[i].parentStory.footnotes.add(LocationOptions.BEFORE, arr1[i].insertionPoints[0], undefined);
myFN.texts[0].insertionPoints[-1].contents = arr2cont[i].substr(4);
}app.findGrepPreferences.findWhat = "^\\[\\d\\].+\\r";
myDoc.changeGrep();
app.findGrepPreferences.findWhat = "\\[\\d+\\]";
myDoc.changeGrep();function GetContents(myArray) {
var myContents =[];
for (i = 0; i < myArray.length; i++) {
myContents.push(myArray[i].contents);
}
return myContents;
}-
FootnoteTestSample.zip 456.5 K
-
-
2. Re: footnotes solution?
pretendermadafaka Sep 27, 2009 9:58 AM (in response to Kasyan Servetsky)thanks man! this works great i tried it!
also i would appreciate if you could teach me how to adopt the script so that it can handle this cases:
in text mark for footnote is [1] and
actual footnote is like this [footnote 1: some text]
and there is one more case were footnote is embedded into text like this ...text[footnote 1:some text] text text...
thanks again for the effort you put into this...i think others will appreciate as well. thank you.
-
3. Re: footnotes solution?
Kasyan Servetsky Sep 28, 2009 3:10 AM (in response to pretendermadafaka)To do what you want you need to change GREP expression:
app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";
But this is not enough. From the scant information you provided, I know that footnote text can be a separate paragraph or a range of text in the middle of a paragraph; colon sometimes is followed by space and sometimes not. The text contains 200+ footnotes — so there is a good chance of mistake to happen — e.g. a footnote entrance is missing the corresponding footnote text. Any such mistake may mess things up.
So I tried to make the script a little fool proofed — now it checks if the corresponding footnote text for the footnote entrance exists before adding footnote.
var myDoc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findGrepPreferences.findWhat = "\\[\\d+\\]";
var arr1 = myDoc.findGrep();
app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";
var arr2 = myDoc.findGrep();
var arr2cont = GetContents(arr2);var myAsArr2 = {};
for (c = 0; c < arr2.length; c++) {
var myIdString = arr2[c].contents;
myIdString = myIdString.match(/\d+/);
myIdString = "[" + myIdString + "]";
myAsArr2[myIdString] = arr2cont[c];
}for (j = arr1.length-1; j >= 0 ; j--) {
var myAsArr2id = eval("myAsArr2[\"[" + (j+1) + "]\"]");
myFN = arr1[j].parentStory.footnotes.add(LocationOptions.BEFORE, arr1[j].insertionPoints[0], undefined);
if (myAsArr2id != undefined) {
myFN.texts[0].insertionPoints[-1].contents = myAsArr2id;
}
else {
myFN.texts[0].insertionPoints[-1].contents = "Text for this footnote has not been found.";
}
}app.findGrepPreferences.findWhat = "\\[\\d+\\]";
app.changeGrepPreferences.changeTo = "";
myDoc.changeGrep();
app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";
myDoc.changeGrep();alert("Done.");
function GetContents(myArray) {
var myContents =[];
for (i = 0; i < myArray.length; i++) {
var myString = myArray[i].contents;
myString = myString.replace(/\[footnote\s?\d+:\s?/, "");
myString = myString.replace(/\]/, "");
myString = myString.replace(/\r$/, "");
myContents.push(myString);
}
return myContents;
}Frankly, I doubt that the script would work as expected with your 'real' document. Because there are lot of conditions that can influence the script and that I'm unaware of yet. And to develop an unfailing script would require much more time then I've already spent.
In the future I recommend you to use the following approach — more simple and reliable. Have you text prepared like so:
This is the text blabla <footnote text>. This is <footnote text> some other text.
All footnotes should be included between brackets (<>).
Then use this script:
app.findGrepPreferences.findWhat = "<.*?>";
app.changeGrepPreferences.changeTo = "";
arrFN = app.documents[0].findGrep(true);
for (i=0; i<arrFN.length; i++) {
myFN = arrFN[i].parentStory.footnotes.add(LocationOptions.BEFORE, arrFN[i].insertionPoints[0], undefined);
myFN.texts[0].insertionPoints[-1].contents = arrFN[i].contents.substr(2);
}app.documents[0].changeGrep();
Kasyan
-
FootnoteTestSample2.zip 452.1 K
-
-
4. Re: footnotes solution?
Kasyan Servetsky Sep 28, 2009 3:37 AM (in response to pretendermadafaka)BTW here is another script that may be of interest to you:
http://forums.adobe.com/thread/459440
Edit: Oops! This one is for notes — not for footnotes. Sorry.

