Thread View: adobe.scripting.indesign
5 messages
5 total messages
Started by Tom_Tomasko
Sat, 03 Jan 2009 06:49
How to find the paragraph and line numbers [CS3] [JS]
Author: Tom_Tomasko
Date: Sat, 03 Jan 2009 06:49
Date: Sat, 03 Jan 2009 06:49
15 lines
1201 bytes
1201 bytes
Hello, I have a script that finds certain text formatting. Rather than having the script select all the instances of this text I have an alert that lists the page number and the contents for each found instance. The following gets those. var pageNumber = myFoundSet[n].parentTextFrames[0].parent.name; var foundContents = myFoundSet[n].contents; However, I would like to include the number of the paragraph where the found text resides as well as the line number in that paragraph. I am stumped on how to do this. Would be nice if there were a parentParagraph and a parentLine. Can someone point me in a direction? Thanks, Tom
Re: How to find the paragraph and line numbers [CS3] [JS]
Author: Robert Tkaczyk
Date: Sat, 03 Jan 2009 08:47
Date: Sat, 03 Jan 2009 08:47
10 lines
974 bytes
974 bytes
read this: CS3 Javascript - finding the paragraph which contain the index page reference http://www.adobeforums.com/webx?14@@.3bbf275d.59b75803/6 robin -- www.adobescripts.com
Re: How to find the paragraph and line numbers [CS3] [JS]
Author: Peter Kahrel
Date: Sat, 03 Jan 2009 12:51
Date: Sat, 03 Jan 2009 12:51
27 lines
1775 bytes
1775 bytes
Assuming that you're looking for the number of the paragraph on the page, you'd need to count the number of paragraphs in the text frame that a found item occurs in. Since indexes are always counted from the beginning of the story, you isolate the text between the top of the page and the found item by starting at the index of the first insertion point of the found item's parent text frame and the found item itself. You capture that with this single long line: // range over ... paragraph_number = myFoundSet[n].parentStory.characters.itemByRange ( // ... index of first ins. point of found item's parent text frame ... myFoundSet[n].parentTextFrames[0].insertionPoints[0].index, // ... and index of found item myFoundSet[n].index ).paragraphs.length; This includes any paragraph that started on the previous page. To find the found item's line number within its parent paragraph you do something similar: line_number = myFoundSet[n].parentStory.characters.itemByRange ( myFoundSet[n].paragraphs[0].index, //first insertion point of paragraph myFoundSet[n].index ).lines.length; Peter
Re: How to find the paragraph and line numbers [CS3] [JS]
Author: Tom_Tomasko
Date: Sat, 03 Jan 2009 16:40
Date: Sat, 03 Jan 2009 16:40
12 lines
1170 bytes
1170 bytes
Peter, Excellent! I have not tried it with the line number but the paragraph number works perfectly. It is rather convoluted how one has to arrive at the end, but I guess that is scripting. Robert, You referred me to another discussion but that is about creating indexes. I had read it earlier but did not find it useful for this problem. Here is a snippet of the code: var paraNumber = myFoundSet[n].parentStory.characters.itemByRange(myFoundSet[n].parentTextFrames[0].insertionPoints[0].index,myFoundSet[n].index).paragraphs.length; Thanks again, Tom
Re: How to find the paragraph and line numbers [CS3] [JS]
Author: Robert Tkaczyk
Date: Sat, 03 Jan 2009 21:49
Date: Sat, 03 Jan 2009 21:49
12 lines
1150 bytes
1150 bytes
hi Tom, > However, I would like to include the number of the paragraph where the found text resides as well as the line number in that paragraph. it wasn't clear for me that you need pragraph's index in TextFrame ;) but this thread was the answer to your question ;) robin -- www.adobescripts.com
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