I am using a script to copy sequential lines from an input text file into an InDesign document. I have used the script a number of times with no problems.
var fi = new File("C:/Documents/input.txt") //Change to the path of your input file
if(!fi.exists)
{
alert("Input file does not exist")
exit()
}
fi.open("r");
var data = fi.read() .split('\n')
app.findGrepPreferences.findWhat = "†"
var res = app.selection[0].parentStory.findGrep(true) //when set to 'false', replace starts from end of input file
data = data.slice(0, res.length)
while(a = res.shift())
{
a.contents = data.pop()
}
app.findGrepPreferences = NothingEnum.nothing;
I am currently working on a file with thousands of footnotes each with the dummy text "†" in the note. I would like to sequentially replace each dummy placeholder with a line from an input file.
The problem is, no matter what I do, the script starts at footnote 18. So, input-line-1 maps to footnote 18, not footnote 1 and so the whole copy and paste is out of sequence.
How can this behaviour be fixed?
I have tried the following:
- delete first frame of story, create new text frame, then re-thread (has the effect of assigning new ID to text frame)
- delete first footnote, then replace again (which did have the effect of searches within InDesign starting from the first footnote, but not so when using the script)
- saving a copy of the document and then trying again with the copied document.
- I have tried a version of the script which uses "var res = app.selection[0].parentStory.findGrep(true)" in line 11 and one that uses "var res = app.documents[0].findGrep(true)"
- I have tried starting the script with my cursor in different positions: in the story, in the footnote, nothing selected
So, how can I get a search in InDesign to begin at the beginning (i.e. from footnote 1, not footnote 18?)
The script uses a GREP search. Would a plain text search work better?
Thank you!