4 Replies Latest reply on Nov 6, 2008 8:08 AM by (Harald_Zwer)

    [CS3] Get the text frame of a topic

    Level 1
      Hello,

      I create a index in InDesign CS3. Each topic has one or more reference.

      myDoc = app.documents[0];
      myIndex = myDoc.indexes[0];
      myTopic = myIndex.topics.item("Folder");
      myRef = myTopic.pageReferences;

      How can I check, if the selected text frame has this reference?

      Thank you in advance

      Harald
        • 1. Re: [CS3] Get the text frame of a topic
          Peter Kahrel Adobe Community Professional & MVP
          > myRef = myTopic.pageReferences

          returns an array of page references. You can cycle through all page references of a topic and then see if the sourceText of a page reference (which is an insertion point) is in the selected text frame. Something like this:

          myDoc = app.documents[0];
          myIndex = myDoc.indexes[0];
          myTopic = myIndex.topics.item("Folder");
          myRef = myTopic.pageReferences;
          for (i = 0; i < myRef.length; i++)
          {
          if (myRef[i].sourceText.parentTextFrames[0] == mySelectedTextFrame)
          // topic "Folder" has a p.ref in the selected text frame
          }

          Peter
          • 2. Re: [CS3] Get the text frame of a topic
            Level 1
            Hello Peter,

            I tried your example, but unfortunately it does not work. The selected frame is not recognized. What can I do?

            Harald
            • 3. Re: [CS3] Get the text frame of a topic
              Peter Kahrel Adobe Community Professional & MVP
              HArald,

              Sorry, I forgot a line, "mySelectedTextFrame = app.selection[0]":

              myDoc = app.documents[0];
              
              myIndex = myDoc.indexes[0];
              myTopic = myIndex.topics.item ("Folder");
              myRef = myTopic.pageReferences;
              mySelectedTextFrame = app.selection[0];

              for (i = 0; i < myRef.length; i++)
                 {
                 if (myRef[i].sourceText.parentTextFrames[0] == mySelectedTextFrame)
                    {
                    alert ("Yes");
                    break;
                    }
                 else
                    alert ("No");
                 }


              Take a document with two text frames on a page, one with some text and a page reference to the topic "Folder", the other one empty. Select the frame that has the page reference in it and the script says "Yes". Select the other frame and the script says "No".

              Peter
              • 4. Re: [CS3] Get the text frame of a topic
                Level 1
                Hello Peter,

                thank you very much!

                It works!

                Harald