4 Replies Latest reply on Jan 3, 2009 1:49 PM by (Robert_Tkaczyk)

    How to find the paragraph and line numbers [CS3] [JS]

    Tom Tomasko Level 1
      Hello,

      I have a script that finds certain text formatting. Rather than having the script select all the instances of this text I have an alert that lists the page number and the contents for each found instance. The following gets those.

      var pageNumber = myFoundSet[n].parentTextFrames[0].parent.name;
      var foundContents = myFoundSet[n].contents;

      However, I would like to include the number of the paragraph where the found text resides as well as the line number in that paragraph.

      I am stumped on how to do this. Would be nice if there were a parentParagraph and a parentLine.

      Can someone point me in a direction?

      Thanks,
      Tom
        • 1. Re: How to find the paragraph and line numbers [CS3] [JS]
          Level 1
          read this:

          CS3 Javascript - finding the paragraph which contain the index page reference

          http://www.adobeforums.com/webx?14@@.3bbf275d.59b75803/6

          robin

          --
          www.adobescripts.com
          • 2. Re: How to find the paragraph and line numbers [CS3] [JS]
            Peter Kahrel Adobe Community Professional & MVP
            Tom,

            Assuming that you're looking for the number of the paragraph on the page, you'd need to count the number of paragraphs in the text frame that a found item occurs in. Since indexes are always counted from the beginning of the story, you isolate the text between the top of the page and the found item by starting at the index of the first insertion point of the found item's parent text frame and the found item itself. You capture that with this single long line:


            // range over ...
            paragraph_number = myFoundSet[n].parentStory.characters.itemByRange (
               // ... index of first ins. point of found item's parent text frame ...
               myFoundSet[n].parentTextFrames[0].insertionPoints[0].index,
               // ... and index of found item
               myFoundSet[n].index
               ).paragraphs.length;


            This includes any paragraph that started on the previous page. To find the found item's line number within its parent paragraph you do something similar:

            line_number = myFoundSet[n].parentStory.characters.itemByRange (
            
               myFoundSet[n].paragraphs[0].index, //first insertion point of paragraph
               myFoundSet[n].index
               ).lines.length;


            There's no need for parentParagraph and parentLine: myFoundSet[n].paragraphs[0] returns an item's parent paragraph, myFoundSet[n].lines[0], the item's parent line.

            Peter
            • 3. Re: How to find the paragraph and line numbers [CS3] [JS]
              Tom Tomasko Level 1
              Peter,
              Excellent! I have not tried it with the line number but the paragraph number works perfectly. It is rather convoluted how one has to arrive at the end, but I guess that is scripting.

              Robert,
              You referred me to another discussion but that is about creating indexes. I had read it earlier but did not find it useful for this problem.

              Here is a snippet of the code:

              var paraNumber = myFoundSet[n].parentStory.characters.itemByRange(myFoundSet[n].parentTextFrames[0].insert ionPoints[0].index,myFoundSet[n].index).paragraphs.length;

              Thanks again,
              Tom
              • 4. Re: How to find the paragraph and line numbers [CS3] [JS]
                Level 1
                hi Tom,

                > However, I would like to include the number of the paragraph where the found text resides as well as the line number in that paragraph.

                it wasn't clear for me that you need pragraph's index in TextFrame ;)

                but this thread was the answer to your question ;)

                robin

                --
                www.adobescripts.com