Skip to main content
December 21, 2009
Answered

Adding paragraph in textFrame using Javascript

  • December 21, 2009
  • 1 reply
  • 9219 views

Hi,

I have a text frame which has 4 paragraphs.

How can I add a 5th paragraph using Javascript and set some content into it?

I tried:

myTextFrame.contents += "\rNew Text"  \\Doesn't works

Also I couldn't find any method available for adding a new paragraph as paragraph property of text frame seems readonly.

Please help!

This topic has been closed for replies.
Correct answer interesting_Flower157F

From the Javascript examples:

//Add text at the end of the text in the text frame.
//To do this, we'll use the last insertion point in the story.
//("\r" is a return character.)
myTextFrame.parentStory.insertionPoints.item(-1).contents = "\rThis is a new paragraph of example text.";

--

Thomas B. Nielsen

http://www.nobrainer.dk

1 reply

interesting_Flower157F
Inspiring
December 21, 2009

From the Javascript examples:

//Add text at the end of the text in the text frame.
//To do this, we'll use the last insertion point in the story.
//("\r" is a return character.)
myTextFrame.parentStory.insertionPoints.item(-1).contents = "\rThis is a new paragraph of example text.";

--

Thomas B. Nielsen

http://www.nobrainer.dk

December 21, 2009

Thanks a lot for that!..

Just wondering if you could help me in following too:

1) If I want to add 3 paragraphs to existing text frame, so using your code, it would be like:

for(i=0;i<3;i++)

{myTextFrame.parentStory.insertionPoints.item(-1).contents = "\rThis is a new paragraph of example text.";}

2) Once I do this, can I simply refer to paragraphs as: mytextFrame.paragraph.item(5)

3) Is there any useful pdf or link where I can get more information on this?

interesting_Flower157F
Inspiring
December 21, 2009

1) If I want to add 3 paragraphs to existing text frame, so using your code, it would be like:

2) Once I do this, can I simply refer to paragraphs as: mytextFrame.paragraph.item(5)

mytextFrame.paragraphs.item(5)

or

mytextFrame.paragraphs[5];

3) Is there any useful pdf or link where I can get more information on this?

Have you looked in the Extendsscript Toolkit (Under help you can see the indesign object model)

Also look here: http://www.adobe.com/products/indesign/scripting/?promoid=DRHXE

Under the scripting tab

--


Thomas B. Nielsen

http://www.nobrainer.dk