You need to prepare some data to alert specific paragraph index.
The solution could be to alert
story is a current text parentStory
startPara is a story.paragraphs
endPara is app.selection.paragraphs;
Use the output, with the help of Jarek coding:
var myStartPara = app.selection.parentStory.paragraphs; alert(myStartPara.contents) var myEndPara = app.selection.paragraphs; alert(myEndPara.contents) var myOutput = app.selection.parentStory.paragraphs.itemByRange(myStartPara, myEndPara).paragraphs.length; alert(myOutput)
@creativejoan0425 – If you selected a table, what is the parent of that table?
Case 1: A text frame with some paragraphs and a table; the one you just selected.
app.selection.parent; //[object TextFrame]
That is leading nowhere. Because the first paragraph of that parent is not the one you are looking for.
Case 2: A text frame with some paragraphs and a table. In cell 1 sits a nested table and in this case that one is selected
app.selection.parent; //[object Cell]
Also this is leading nowhere.
Ok. What can we do? Look up the DOM documentation for the Object Table:
Here we can find a property that will guide us for Case 1:
Now, what is the storyOffset of the object Table?
"The insertion point before the table in the story containing the table."
For case 1 in my two case scenario you can directly work with storyOffset.
app.selection; //[object Table] app.selection.storyOffset; //[object InsertionPoint] app.selection.storyOffset.index //Position of storyOffset in story app.selection.storyOffset.parentStory //[object Story] app.selection.storyOffset.parentStory.characters[app.selection.storyOffset.index].tables; //[object Table] (my selected table) //The length of all paragraphs from the beginning of the STORY to the paragraph of my selected table: app.selection.storyOffset.parentStory.insertionPoints.itemByRange(0 , app.selection.storyOffset.index).paragraphs.length;
If you want to select the paragraph that is holding your table, simply do like that:
Note 1: But you are misleaded, if you think, that the index of that paragraph will give you the number of that paragraph in its parent story:
"Unfortunately" that is giving you the index of the character, that is holding your table:
You can also write (same result) to select the character that is holding your selected table:
Note 2: In case 2, the scenario with the nested table, we have to do another workaround to get the paragraph.
Note 3: If the text frame is not the first one in the story and you want to know the number of the paragraph in relation to that text frame, we have to do some things additionally to substract all paragraphs of all text frames before the one your selected table is sitting in.