3 Replies Latest reply on Jan 17, 2015 10:13 AM by Laubender

    Alert Selected Table Paragraph

    creativejoan0425 Level 1

      I have 5 paragraphs, when I selection the table I want to alert the paragraph item, it should be 5;

      but the result is [object Paragraphs]




        • 1. Re: Alert Selected Table Paragraph
          Jump_Over Level 5



          You need to prepare some data to alert specific paragraph index.

          The solution could be to alert

          story.paragraphs.itemByRange(startPara, endPara).texts[0].paragraphs.length;



          story is a current text parentStory

          startPara is a story.paragraphs[0]

          endPara is app.selection[0].paragraphs[0];



          • 2. Re: Re: Alert Selected Table Paragraph
            BEGINNER_X Level 3

            Hi Creative,


            Use the output, with the help of Jarek coding:


            var myStartPara = app.selection[0].parentStory.paragraphs[0];
            var myEndPara = app.selection[0].paragraphs[0];
            var myOutput = app.selection[0].parentStory.paragraphs.itemByRange(myStartPara, myEndPara).paragraphs.length;




            • 3. Re: Alert Selected Table Paragraph
              Laubender Adobe Community Professional & MVP

              @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[0].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[0].parent; //[object Cell]


              Also this is leading nowhere.


              Ok. What can we do? Look up the DOM documentation for the Object Table:

              Adobe InDesign CS6 (8.0) Object Model JS: Table


              Here we can find a property that will guide us for Case 1:


              Adobe InDesign CS6 (8.0) Object Model JS: Table


              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.

              Here some lines of code you could work with in the ESTK one after another to check the readout in the JavaScript Console:


              app.selection[0]; //[object Table]
              app.selection[0].storyOffset; //[object InsertionPoint]
              app.selection[0].storyOffset.index //Position of storyOffset in story
              app.selection[0].storyOffset.parentStory //[object Story]
              app.selection[0].storyOffset.parentStory.characters[app.selection[0].storyOffset.index].tables[0]; //[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[0].storyOffset.parentStory.insertionPoints.itemByRange(0 , app.selection[0].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.