Yes I understand how to select a range of objects whatever they may be.
What I need is how to return the index of a paragraph or line (within the document) in which my word is found.
I can find the word. What is the index of the paragraph or line in which it is found?
That's it. The rest is no problem.
Thanks for your response.
I'm not sure I understand you question entirely.
You want to know all of the places in a document are particular variable is? For instance you're looking for the keyword 'Apple' and you want to know in which paragraphs this particular word appears?
Yes that's exactly what I want. Then I can reference each paragraph (in which the keyword is found) by it's index within the document.
Unless I'm looking at this entirely wrong.
"The" index of a paragraph is nothing special, it's the index of the first character of that paragraph inside its parent story. In particular, it does NOT tell you "this is the 5th paragraph" or something like that.
This is because "Paragraph" is an artificial construct inside "Text", not a truly existing first class object. Same as "Line", "Word", "Character", and indeed, any text selection at all.
Since you already have a "found text" array, "the index" of the nth entry's paragraph -- with the constraint described above -- can be simply found by using foundText[n].paragraphs.index (the index of the first character of your foundText is foundText[n].index).
If you DO need to know the nth number of the paragraph, search this forum. I think Peter Kahrel answered to a post to answer that exact question.
I think I see what you're saying Jongware.
var paraRef = app.activeDocument.stories.everyItem().paragraphs.itemByRange(2,9);
select the third through 10th paragraphs in the story.
Those are the kinds of numbers I need to get.
I'll have a search through the forum again to see if I can find the solution.
I'm having a hard time grasping the ins and outs of the InDesign Object Model. I bought book on scripting InDesign and it's helping but it's just going to take time to get my head around it all.
Thanks for your help everyone.