Thread View: adobe.scripting.indesign
20 messages
20 total messages
Started by Ola_Khrapatin
Tue, 23 Dec 2008 21:32
CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Tue, 23 Dec 2008 21:32
Date: Tue, 23 Dec 2008 21:32
12 lines
1143 bytes
1143 bytes
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
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Tue, 23 Dec 2008 21:55
Date: Tue, 23 Dec 2008 21:55
5 lines
749 bytes
749 bytes
The parent of the sourceText is the story. You want sourceText.paragraphs[0] Dave
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Thu, 25 Dec 2008 20:22
Date: Thu, 25 Dec 2008 20:22
10 lines
1179 bytes
1179 bytes
Well, that is a good way to have the paragraph which contains the index marker. My problem is, that I want to find the index of this paragraph in the story. I mean, is it the 1st, 2nd, 3rd, or 4th (etc) paragraph in the story. The reason I need to find this index is that I want to use it in the option of setting a topic's page references page range according to a specific number of paragraphs. For example: INDEX Cat, 18 Dogs, 20-25 [from a paragraph on page 20, to a paragraph on page 25] How can I find the number of my paragraph?
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Robert Tkaczyk
Date: Thu, 25 Dec 2008 22:17
Date: Thu, 25 Dec 2008 22:17
10 lines
1190 bytes
1190 bytes
if you need to get page - you don't need paragraph index - you can get page by getting parent of ParentTextFrame of first character of your paragraph in VB it will be something like this: PageName = myPara.Characters.Item(1).ParentTextFrames.Item(1).Parent.Name robin -- www.adobescripts.com
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Fri, 26 Dec 2008 00:52
Date: Fri, 26 Dec 2008 00:52
9 lines
3904 bytes
3904 bytes
<div dir="rtl">You are right. This is also an option. But for my specific script I need it to be according to paragraphs because the page numbers might change, you see, and with paragraphs it is very accurate. I am sure there is some reasonable way to achieve this, but I failed to find it so far... Any clues?<br> <br> <div><span class="gmail_quote">2008/12/26, Robert_Tkaczyk <<a href="mailto:member@adobeforums.com">member@adobeforums.com</a>>:</span> <blockquote class="gmail_quote" style="BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 1ex; PADDING-LEFT: 1ex; MARGIN: 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">A new message was posted by Robert_Tkaczyk in<span class="q"><br> <br>InDesign Scripting --<br> CS3 Javascript - finding the paragraph which contain the index page reference<br><br></span>if you need to get page - you don't need paragraph index - you can get page by getting parent of ParentTextFrame of first character of your paragraph<br> <br>in VB it will be something like this:<br><br>PageName = myPara.Characters.Item(1).ParentTextFrames.Item(1).Parent.Name<br><br>robin<br><br>-- <br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobescripts.com/" target="_blank">www.adobescripts.com</a><br> <br><br>------------------------------------------------------<br>View/reply at <<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?13@@.59b75803/2" target="_blank">http://www.adobeforums.com/webx?13@@.59b75803/2</a>><span class="q"><br> Replies by email are OK.<br></span>Use the unsubscribe form at <<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?280@@.59b75803!folder=.eea52bc" target="_blank">http://www.adobeforums.com/webx?280@@.59b75803!folder=.eea52bc</a>> to cancel your email subscription.<br> </blockquote></div><br></div>
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Fri, 26 Dec 2008 01:45
Date: Fri, 26 Dec 2008 01:45
8 lines
983 bytes
983 bytes
I don't get it. The paragraphs are just as likely to change if you're contemplating later editing. Anyway, the way to get the number of paragraphs is: myPara = app.activeDocument.indexes.item(0).topics.item(0).pageReferences.item(0).sourceText.paragraphs[0] myPcount = myPara.parent.texts.itemByRange(0, myPara.index).paragraphs.length; Dave
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Fri, 26 Dec 2008 15:44
Date: Fri, 26 Dec 2008 15:44
27 lines
2024 bytes
2024 bytes
Hi, it seems your lines should have solved the issue, but I usually get an error saying "object is invalid" on the second line. It works only if I remove the end: myPara = app.activeDocument.indexes.item(0).topics.item(0).pageReferences.item(0).sourceText.paragraphs[0] myPcount = myPara.parent.texts.itemByRange(0, myPara.index)//.paragraphs.length; Did you try to run these lines and it worked fine? You know, I think I write the bigger picture: I am getting a Word file to typeset with index markers inside. The only problem is that Word recognizes PAGE RANGES, while InDesign does not (I mean the ones coming from Word). So my text editor and I agreed on specail "signs" to show where a page range begings and ends. For example: INDEX DogsYYY, 15 DogsZZZ, 20 When I see this I know i need to change the index marker in InDesign to be like that: INDEX Dogs, 15-20 Now, when you do it on 1, 2, 3 index markers, it is not so bad. But if you do it on hundreds of them - the fun stops ;) pretty crazy, ha? So the goal is to make a script to do this simple mechanical action. And this is the bigger picture. I didn't find anything on the internet for it, which is quite surprising... Doesn't anyone else get their text from Word with index markers and page ranges? Anyway, any sort of help will be greatly appriciated, as I am a *bit* closer to desperate. Ola
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Fri, 26 Dec 2008 16:06
Date: Fri, 26 Dec 2008 16:06
5 lines
830 bytes
830 bytes
I didn't actually try it and I'm in an Apple Store right now. I think I left out texts[0]. Try this: myPcount = myPara.parent.texts.itemByRange(0, myPara.index).texts[0].paragraphs.length; Dave
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Fri, 26 Dec 2008 16:45
Date: Fri, 26 Dec 2008 16:45
27 lines
2145 bytes
2145 bytes
Hi, thanks for the quick reply! I tryed the revised version and it worked by itslef, so I guess that really was the missing link. Now, when I combined these 2 lines inside the bigger version, it failed to work. This is the script (Do you have any idea what's the bug?): //InDesign CS3 Javascript //Not working properly. Supposed to combine 2 different index markers into a single index marker containing 1 page range //according to the original index markers location //The real script has loops and counters, here I simplified it to see what exactely went wrong: myIndex = app.activeDocument.indexes.item(0); myTopics = myIndex.topics; myTopic1 = myTopics.item(0); myPara1 = myTopics.item(0).pageReferences.item(0).sourceText.paragraphs.item(0); //The location of the first index marker: myPara1Place = myPara1.parent.texts.itemByRange(0, myPara1.index).texts.item(0).paragraphs.length; myTopic2 = myTopics.item(1); myPara2 = myTopics.item(1).pageReferences.item(0).sourceText.paragraphs.item(0); //The location of the second index marker: myPara2Place = myPara1.parent.texts.itemByRange(0, myPara1.index).texts.item(0).paragraphs.length; //sets the page reference to refer to a page range based on paragraphs: myTopic1.pageReferences.item(0).pageReferenceType = PageReferenceType.forNextNParagraphs; myLimit = myPara2Place - myPara1Place; myTopic1.pageReferences.item(0).pageReferenceLimit = myLimit; //Removes the second and uneeded topic myTopic2.pageReferences.item(0).remove();
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Fri, 26 Dec 2008 16:54
Date: Fri, 26 Dec 2008 16:54
3 lines
684 bytes
684 bytes
Typo. You got the same paragraph count twice. Dave
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Fri, 26 Dec 2008 17:10
Date: Fri, 26 Dec 2008 17:10
4 lines
1018 bytes
1018 bytes
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);
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Sat, 27 Dec 2008 00:19
Date: Sat, 27 Dec 2008 00:19
3 lines
779 bytes
779 bytes
Well, it is possible for a topic to exist that lacks page references. Perhaps that's the problem. Dave
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Sun, 28 Dec 2008 21:01
Date: Sun, 28 Dec 2008 21:01
8 lines
1032 bytes
1032 bytes
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
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Sun, 28 Dec 2008 22:58
Date: Sun, 28 Dec 2008 22:58
3 lines
928 bytes
928 bytes
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
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Mon, 29 Dec 2008 16:52
Date: Mon, 29 Dec 2008 16:52
3 lines
777 bytes
777 bytes
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.
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Peter Kahrel
Date: Sat, 03 Jan 2009 11:56
Date: Sat, 03 Jan 2009 11:56
8 lines
953 bytes
953 bytes
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
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Sun, 04 Jan 2009 11:18
Date: Sun, 04 Jan 2009 11:18
11 lines
3729 bytes
3729 bytes
<div dir="rtl"><div>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?</div> <div> </div> <div>Ola<br><br> </div> <div><span class="gmail_quote">2009/1/3, Peter Kahrel <<a href="mailto:member@adobeforums.com">member@adobeforums.com</a>>:</span> <blockquote class="gmail_quote" style="BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 1ex; PADDING-LEFT: 1ex; MARGIN: 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">A new message was posted by Peter Kahrel in <br><br><b>InDesign Scripting</b> --<br> CS3 Javascript - finding the paragraph which contain the index page reference<br><br>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: <blockquote><tt>myPcount = myPara.parentStory.characters.itemByRange(0, myPara.index).paragraphs.length; </tt></blockquote><br><br>Peter <br><br> <hr align="left" width="200"> View/reply at <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?13@@.59b75803/14" target="_blank">CS3 Javascript - finding the paragraph which contain the index page reference</a><br> Replies by email are OK.<br>Use the <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?280@@.59b75803!folder=.eea52bc" target="_blank">unsubscribe</a> form to cancel your email subscription.<br> <br></blockquote></div><br></div>
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Peter Kahrel
Date: Sun, 04 Jan 2009 11:57
Date: Sun, 04 Jan 2009 11:57
12 lines
1306 bytes
1306 bytes
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
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Ola_Khrapatin
Date: Mon, 05 Jan 2009 11:20
Date: Mon, 05 Jan 2009 11:20
12 lines
3896 bytes
3896 bytes
<div dir="rtl">Thank you, I'll check that one and post an update...<br><br> <div><span class="gmail_quote">2009/1/4, Peter Kahrel <<a href="mailto:member@adobeforums.com">member@adobeforums.com</a>>:</span> <blockquote class="gmail_quote" style="BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 1ex; PADDING-LEFT: 1ex; MARGIN: 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span class="q">A new message was posted by Peter Kahrel in <br> <br><b>InDesign Scripting</b> --<br> CS3 Javascript - finding the paragraph which contain the index page reference<br><br></span> <blockquote><tt>myPara1Place = myPara1.parent.texts.itemByRange(0, myPara1.index) </tt></blockquote><br><br>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. <br> <br>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. <br> <div><span class="e" id="q_11ea18e2684e2070_2"><br>Peter <br><br> <hr align="left" width="200"> View/reply at <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?13@@.59b75803/16" target="_blank">CS3 Javascript - finding the paragraph which contain the index page reference</a><br> Replies by email are OK.<br>Use the <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.adobeforums.com/webx?280@@.59b75803!folder=.eea52bc" target="_blank">unsubscribe</a> form to cancel your email subscription.<br> <br></span></div></blockquote></div><br></div>
Re: CS3 Javascript - finding the paragraph which contain the index page reference
Author: Dave_Saunders
Date: Mon, 05 Jan 2009 13:41
Date: Mon, 05 Jan 2009 13:41
7 lines
905 bytes
905 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads