Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add a paragraph and get a reference to it

Community Expert ,
Oct 28, 2008 Oct 28, 2008
Hello All,

I am using the following to add a new paragraph after the one containing the insertion point:

// Get a reference to the selected paragraph.
var oPgf = app.selection[0].paragraphs[0];
// Add a blank paragraph.
oPgf.insertionPoints[-1].contents = '\r';

I want to get a reference to the new paragraph without having to query the document's selection. So given a paragraph object oPgf, what is the best way to add a paragraph after it and return a reference to the new paragraph? Thank you very much.

Rick Quatro
rick at frameexpert dot com
585-659-8267
TOPICS
Scripting
517
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2008 Oct 28, 2008
Hi Rick,

Either of the following lines will get you a reference to the next paragraph:

var nPgf = oPgf.insertionPoints[-1].paragraphs[0];

var nPgf = oPgf.parentStory.paragraphs.nextItem (oPgf);

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 28, 2008 Oct 28, 2008
Hi Peter,

I have found out that multiple use of nextItem() can slow down the processing of a script.
So I often use a workaround like this to get the next paragraph of a found paragraph within a story (not within a footnote):


// found paragraph
var myPara = myFoundItems;

// count of paragraphs from the beginning of a story until the found paragraph
var myParaIndex = myFoundItems.parentStory.insertionPoints.itemByRange( 0, myPara.index ).paragraphs.length;

// paragraph after the found paragraph
var myNextPara = myFoundItems.parentStory.paragraphs[myParaIndex + 1];


Martin
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2008 Oct 28, 2008
Martin,

next/previousItem() can get slow indeed. Interesting solution you have there. But I think that that first line I gave is quicker because it doesn't refer to the parentStory and all the paragraphs in it: nPgf = oPgf.insertionPoints[-1].paragraphs[0];

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 28, 2008 Oct 28, 2008
LATEST
Peter,

of course, you are right.
I should have read your message with more strength.

Martin
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines