Skip to main content
Known Participant
December 23, 2008
Question

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

  • December 23, 2008
  • 28 replies
  • 3952 views
Hi,
I've been trying to cook a script which has the following function:
It gets a topic's page reference, and return the index in the story of the paragraph which contains the source text. I figured the line should look something like that (i made it specific for the example):

myParagraphIndex = app.activeDocument.indexes.item(0).topics.item(0).pageReferences.item(0).sourceText.parent.index;

The problem is, that this line return the index of the parent story.

How can I get the index of the containing paragraph??

Thanks,
Ola
This topic has been closed for replies.

28 replies

Inspiring
January 5, 2009
Ola,

Could you suppress the quoting of messages in your replies here, please. It's not really necessary to quote whole messages because the message is right here on the forum.

Small quotes to highlight a particular point are, of course, welcome.

Dave
Ola_KAuthor
Known Participant
January 5, 2009
Thank you, I'll check that one and post an update...


2009/1/4, Peter Kahrel < member@adobeforums.com>:
A new message was posted by Peter Kahrel in


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


myPara1Place = myPara1.parent.texts.itemByRange(0, myPara1.index)


myPara1.index returns the index of the first insertion point of the current paragraph within the story (myPara1.parent is a story), which could be in the thousands. But you're addressing probably just one text. It's as if you're asking for twenty lollies when there's just one in the jar.


When you use someobject.itemByRange (start, stop), "stop" must be smaller than (or equal to) the length of "someobject". Since there are (probably) as many characters in a story as there are indexes, in this case that's what you use for itemByRange's scope.



Peter




View/reply at CS3 Javascript - finding the paragraph which contain the index page reference

Replies by email are OK.
Use the unsubscribe form to cancel your email subscription.



Peter Kahrel
Community Expert
Community Expert
January 4, 2009
>myPara1Place = myPara1.parent.texts.itemByRange(0, myPara1.index)

myPara1.index returns the index of the first insertion point of the current paragraph within the story (myPara1.parent is a story), which could be in the thousands. But you're addressing probably just one text. It's as if you're asking for twenty lollies when there's just one in the jar.

When you use someobject.itemByRange (start, stop), "stop" must be smaller than (or equal to) the length of "someobject". Since there are (probably) as many characters in a story as there are indexes, in this case that's what you use for itemByRange's scope.

Peter
Ola_KAuthor
Known Participant
January 4, 2009
I didn't quite get it, how is it that it tries to range over far more texts than in the story? How is it different with the characters?

 

Ola

 

2009/1/3, Peter Kahrel < member@adobeforums.com>:
A new message was posted by Peter Kahrel in

InDesign Scripting --

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

myPara.index is the index of myPara's first insertion point, so ...texts.itemByRange (0, myPara.index) tries to range over far more Texts than there are in the story. Instead, range over characters:
myPcount = myPara.parentStory.characters.itemByRange(0, myPara.index).paragraphs.length;


Peter




View/reply at CS3 Javascript - finding the paragraph which contain the index page reference

Replies by email are OK.
Use the unsubscribe form to cancel your email subscription.



Peter Kahrel
Community Expert
Community Expert
January 3, 2009
myPara.index is the index of myPara's first insertion point, so ...texts.itemByRange (0, myPara.index) tries to range over far more Texts than there are in the story. Instead, range over characters:
>myPcount = myPara.parentStory.characters.itemByRange(0, myPara.index).paragraphs.length;

Peter
Ola_KAuthor
Known Participant
December 29, 2008
In my case it isn't the last paragraph, so I guess the problem is something with my syntex.

understood. We wish you all health.
Inspiring
December 28, 2008
If you have an index item at the very end of a story, there is no paragraph there. That could be it. (I've been away from my computer all day because my daughter is in hospital having lost her baby after carrying him for eight months, so I'm more than a little distracted.)

Dave
Ola_KAuthor
Known Participant
December 28, 2008
Yup, that was the problem indeed.

Then it got stuck on the following line:
myPara1Place = myPara1.parent.texts.itemByRange(0, myPara1.index).texts.item(0).paragraphs.length;

using the Debuging tools I could see it probabely has something to do with the "itemByRange" result. What could be the bug?...

Ola
Inspiring
December 27, 2008
Well, it is possible for a topic to exist that lacks page references. Perhaps that's the problem.

Dave
Ola_KAuthor
Known Participant
December 26, 2008
Thanks, I fixed it now. [myPara2Place = myPara1.parent.texts.itemByRange(0, myPara2.index).texts.item(0).paragraphs.length;]

But actually the script failed much eariler. I get the message "object is invalid" on the 4th line:
myPara1 = myTopics.item(0).pageReferences.item(0).sourceText.paragraphs.item(0);