4 Replies Latest reply on Nov 10, 2008 9:22 AM by Ildhund

    [CS3][JS] Return first page for story

    Ildhund Level 3
      I'm bogged down trying to find a simple way to return the number of
      the first page that a particular story appears on, assuming that it
      is placed on a page and not all overset. Or the number of the page
      that the first word in the story appears on, or something like that.
      Can anyone help a beginner?
        • 1. Re: [CS3][JS] Return first page for story
          Peter Kahrel Adobe Community Professional & MVP
          One of the most elusive properties in InDesign/JS is "page number" -- which is ironic in a page-layout program. It is in fact the name of a page:

          • 2. Re: [CS3][JS] Return first page for story
            Level 1
            Pages also have a documentOffset property that might be more useful than the page name (depending on your intentions). It's a number while the name is a string. But the documentOffset ignores any formatting you might have done to the page name, and also is independent of any numbering changes you might have made with your sections.

            • 3. Re: [CS3][JS] Return first page for story
              (Simon_Paterson) Level 1
              > myStory.textContainers[0].parent.name

              This will not work if the frame is in a group (which most of the time is not the case, so it probably doesn't matter). But just in case, the following method will reliably find the correct page, but is not necessarily the most efficient, depending on the number of pages in the document.

              >var myFrame = myStory.textContainers[0];

              var myPage = GetPageOfFrame(myFrame);

              var myPageName = myPage.name; // the page's folio, a string

              var myPageOffset = myPage.documentOffset; // the nth page of the document, a number

              function GetPageOfFrame(theFrame)


              ]for (var p = 0; p < app.documents[0].pages.count(); pi++)


              ]]var myPageItems = app.documents[0].pages[p].allPageItems;

              for (var pi = 0; pi < myPageItems.length; p++)


              ]]]if (myPageItems[pi] == myFrame)


              ]]]]return app.documents[0].pages[p];





              There's a another method to deal with frames in a group (or group of groups), which involves a recursive handler to keep looking at the parent of the parent, etc, but the one I use is flawed in certain circumstances so I use this one when reliability is important.
              • 4. Re: [CS3][JS] Return first page for story
                Ildhund Level 3
                Thanks to you all. At least that bit is now working! I'll salt your
                pearls of wisdom away for future use.