4 Replies Latest reply on Mar 23, 2011 3:39 AM by BeriliaTubul

    [JS] number of all PageReferences of all Topics

    BeriliaTubul Level 1

      Hi,

       

      I'm trying to make a progress bar while the treatment of my topics and (obviously) I need to know how much pageReferences of my topics I have in my document.

       

      With this I know how many topics there is :

      myDocument.indexes.item(0).allTopics.length

      but for each topic I can have many pageReferences. How can I know how much there is?

       

       

      An other question :

      Is there a possibility to start the treatment of the topics at the beginning of the document?

       

      for example :

      chicken at page 2

      egg at page 1 and 3

      (Just an example...)

       

      I would like to treat egg at page 1, then chicken at page 2, and egg at page 3.

       

      For now I do chicken then egg (1) then egg (2).

       

      Hope someone will help me!

        • 1. Re: [JS] number of all PageReferences of all Topics
          Peter Kahrel Adobe Community Professional & MVP

          You can probably get the number of page references as follows:

           

          myTopic.pageReferences.length;

           

          >I would like to treat egg at page 1, then chicken at page 2, and egg at page 3.

           

          That's more like a table of contents than an index.

           

          Peter

          • 2. Re: [JS] number of all PageReferences of all Topics
            BeriliaTubul Level 1

            Thant you for answering.

             

            Yes, I know I can do that, but that's not what I am looking for.

             

            I need something who would take myStory and returns all the topics who were found (and who have a page reference).

             

             

             

            No, no, it's an index!

            (My english is maybe bad, I'm sorry, I'm french and I'm not very good in english...)

            • 3. Re: [JS] number of all PageReferences of all Topics
              Peter Kahrel Adobe Community Professional & MVP

              Aha -- you want to find topics/page references for a story? That's a bit more complicatedbecause topics are children of the index, and the index is a child of the document. So there's no direct link between topics/page references and stories. So what you would need to do is to get all page references, get each one's parent story (using sourceText), compare it with your story, and if the two stories are the same, put the page reference's parent topic somewhere, e.g. in an array.

               

              Given a reference story MyStory, this script

               
              // Collect all page references
              PRefs = app.documents[0].indexes[0].topics.everyItem().pageReferences.everyItem().getElements();
              StoryTopics = [];
              for (i = 0; i < PRefs.length; i++)
                  // PRefs[i].sourceText is an InsertionPoint
                  if (PRefs[i].sourceText.parentStory == MyStory)
                      PRefs[i].parent.push (StoryTopics);

               

              places all topics that occur in myStory in the array StoryTopics. You could represent your topics/stories in several different ways, your choice depends on what you want to do with your data.

               

              Peter

              • 4. Re: [JS] number of all PageReferences of all Topics
                BeriliaTubul Level 1

                Thank you for your answer.

                It was exactly what I was looking for!