Skip to main content
Known Participant
November 5, 2008
Question

[CS3] Get the text frame of a topic

  • November 5, 2008
  • 4 replies
  • 372 views
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
This topic has been closed for replies.

4 replies

Known Participant
November 6, 2008
Hello Peter,

thank you very much!

It works!

Harald
Peter Kahrel
Community Expert
Community Expert
November 5, 2008
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.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
Known Participant
November 5, 2008
Hello Peter,

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

Harald
Peter Kahrel
Community Expert
Community Expert
November 5, 2008
> 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.sourceText.parentTextFrames[0] == mySelectedTextFrame)
// topic "Folder" has a p.ref in the selected text frame
}

Peter