Thread View: adobe.scripting.indesign
4 messages
4 total messages
Started by Rick_Quatro
Tue, 06 Jan 2009 17:08
[CS3 JS] Finding paragraph containing table
Author: Rick_Quatro
Date: Tue, 06 Jan 2009 17:08
Date: Tue, 06 Jan 2009 17:08
29 lines
1582 bytes
1582 bytes
I have a table object and want to find the paragraph that contains the table. Then I want to return the contents of the paragraph previous to the table anchor. I am using this, but when I attempt to display the contents of the paragraph, I get "Object is invalid". Thanks for any help you can provide.
// Get the paragraph inside the table.
var oPgf = app.selection[0].paragraphs[0];
// Make sure the paragraph is in a cell.
if (oPgf.parent.constructor.name === "Cell") {
// Get the parent cell and table objects.
var oCell = oPgf.parent;
var oTbl = oCell.parent;
// Get the paragraph containing the table.
var oPgf2 = oTbl.storyOffset.paragraphs[0];
// Get the story object of the paragraph.
var oStory = oPgf.parentStory;
// Get the paragraph's index.
var iPos = oPgf2.index;
// Display the contents of the paragraph before the table anchor.
alert (oStory.paragraphs[iPos-1].contents);
}
Rick Quatro
585-659-8267
Re: [CS3 JS] Finding paragraph containing table
Author: Dave_Saunders
Date: Tue, 06 Jan 2009 19:13
Date: Tue, 06 Jan 2009 19:13
5 lines
774 bytes
774 bytes
That's because the index is a count of the characters in the story. You need: alert(oStory.characters[iPos-1].paragraphs[0].contents); Dave
Re: [CS3 JS] Finding paragraph containing table
Author: Rick_Quatro
Date: Tue, 06 Jan 2009 21:07
Date: Tue, 06 Jan 2009 21:07
3 lines
765 bytes
765 bytes
OK, I think I get it. How do I get the index of the paragraph so I can loop through the paragraph's previous to the table? Thanks. Rick
Re: [CS3 JS] Finding paragraph containing table
Author: Rick_Quatro
Date: Tue, 06 Jan 2009 21:32
Date: Tue, 06 Jan 2009 21:32
32 lines
1491 bytes
1491 bytes
I found a previous post that is helping me with this.
// Paragraph inside of table.
var oPgf = app.selection[0].paragraphs[0];
// Make sure the paragraph is inside a table
if (oPgf.parent.constructor.name === "Cell") {
var oCell = oPgf.parent;
var oTbl = oCell.parent;
// Get the paragraph containing the table anchor.
var oPgf2 = oTbl.storyOffset.paragraphs[0];
// Loop from the table anchor to the top of the story.
while (oPgf2) {
$.writeln(oPgf2.constructor.name);
oPgf2 = oPgf2.parentStory.paragraphs.previousItem(oPgf2);
}
}
This basically works, except this line gives an "Object is invalid" error when it gets to the beginning of the story:
oPgf2 = oPgf2.parentStory.paragraphs.previousItem(oPgf2);
I can use a try statement, but I am wondering why the loop doesn't exit gracefully without an error. Thanks.
Rick
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