Skip to main content
A2D2
Inspiring
November 5, 2019
Answered

Search does not start at beginning

  • November 5, 2019
  • 2 replies
  • 1224 views

Manan Joshi kindly write a script to copy sequential lines from an input text file into a document. I have used the script a number of times with no problems.

 

The script and the discussion can be found here.

 

I am currently working on a file with 3,644 footnotes each with the dummy text "¢†". I would like to sequentially replace each 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:

 

  1. delete first frame of story, create  new text frame, then re-thread
  2. 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)
  3. saving a copy of the document and then trying again with the copied document.
  4. I have tried both the version of the script which uses "var res = app.selection[0].parentStory.findGrep(true)" in line 11 and the version that has "var res = app.documents[0].findGrep(true)"
  5. I have tried starting the script with my cursor in different positions: in the story, in the footnote, nothing selected

 

I am posting a new thread because I think the problem may be more general than the way the script linked above works.

 

Thank you!

This topic has been closed for replies.
Correct answer A2D2

@brianp311 -

That's a good point.

OP - You could try telling the script to not include master pages by including the line:

app.findChangeGrepOptions.includeMasterPages = false;

above the findGrepPreferences line in that original script. That would rule out master pages, at least.


Thank you for the helpful suggestions. There are only 4 master pages and no footnotes in there (I also checked hidden layers etc.)

 

The script seems fine and the input file seems fine so I began focussing on the document.

 

I found some footnotes in tables that were hidden as invisible formatting. The footnote markers were displaying as "<?>". These <?> markers show as dynamic footnotes in story editor and I can right click them and choose "Go to Footnote Text" in the contextual menu.

 

Notes cannot be inserted in a table. The relevant menu option is disabled. These phantom notes came into being through a find and replace, where the found item was replaced with the clipboard contents (which happened to be a footnote)

 

These phantom notes are not included in the footnote marker sequence so I get a sequence of markers as follows:

...2908, 2909, <?>, <?>, <?>, 2910, 2911...

 

However, the corresponding footnote text sequence does not jump so I get:

...2908, 2909, 2910, 2911, 2912, 2913, 2914...

 

Hence, there is a mismatch.

 

I got rid of the mismatch and finished what I needed to do. Thanks again for your support.

2 replies

brian_p_dts
Community Expert
Community Expert
November 6, 2019

Something is likely different in this particular input file than previous ones. Is there an extra carriage return at the start of the file? That would be where I investigate first if the script worked fine on previous inputs. 

A2D2
A2D2Author
Inspiring
November 6, 2019

Thank you for the suggestion. The input file seems fine. I opened it up with Notepad++ to look for hidden characters, extra carriage returns etc...but nothing.

 

There are precisely 3,644 notes in the ID document and precisely 3,644 lines in the input text file.

 

Every line in the input text file ends in a carriage return apart from the last (because there is nothing after it).

 

Interestingly, I entered an extra carriage return at the end of the document and executed the script. Instead of pasting from footnote 18 the script began pasting at footnote 17 and, accordingly, finished a line early. With 3 carriage returns at the end of the input file the script began pasting at footnote 15...I don't know what that is about.

 

Within the ID document I did a find/replace for the "¢†" placeholder and 3,661 are found...17 more than the 3,644 that are actually there. I did more searches to check there were not any "¢†" in the text or there were not 2 in 1 footnote but could not.

 

So, the script seems fine and the input file seems fine but there is something with the document. I don't know what it could be. The document is in Arabic, for what it is worth, but can't see what difference that would make because the Arabic font has Unicode encoding.

brian_p_dts
Community Expert
Community Expert
November 6, 2019

Is the "¢†" placeholder text in the document's master pages? Do you have maybe 17 master pages where that text would appear in each. I'm not sure, but I think a doc.findGrep search would also find items in master pages. I'd check there. 

A2D2
A2D2Author
Inspiring
November 5, 2019

When I run the script I get an error message and then when I click OK the script executes. With a test document I would only get this error if the cursor was not in the story and when I clicked OK nothing happened.

 

JavaScript Error!

 

Error Number: 30477

Error String: Invalid value for set property 'contents'. Expected

String or SpecialCharacters enumerator, but received nothing.

 

Engine: main

File: C:Users\[Username]\AppData\Roaming\Adobe\InDesign\Version

8.0\en_GB\Scripts Panel\automatic-paste_entire-doc.jsx

Line: 15

Source:    a.contents = data.pop()

 

A2D2
A2D2Author
Inspiring
November 6, 2019

I also tried a plain text search rather than GREP, using "app.findTextPreferences" in line 10. The script starts pasting at footnote 1 (as desired) but then restarts at footnote 18 (not desired!). The pasting is then all out of sequence with the gap eventually narrowing and then everything is in sequence from not 2,914 until the end (strange!)