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

Adding content to a textframe

Community Expert ,
Nov 24, 2012 Nov 24, 2012

Hi all,

I want to add some content to a textframe which already has some text in it. If i use the following code

tframe.content += "appended text"

then the text is appended to the textframe but all the text that was previously present in the the textframe has their paragraph style  reset to the paragraph style of the new text.

What i need is that the paragraph style of the original text should not change and the new text takes up the paragraph style of the para in which it is added.

Second issue is how do i add a special character like a Em-Dash to the text that i want to place in the textframe. If i use the enum like SpecialCharacters.EM_DASH it displays a number(the value of the enum) in the frame but not the actual character.

Thanking all of you in anticipation of great suggestions as always.

Manan

TOPICS
Scripting
1.4K
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

correct answers 1 Correct answer

Community Expert , Nov 24, 2012 Nov 24, 2012

Add some text to a text frame:

tframe.parentStory.insertionPoints[-1].contents = " appended text"

For an em-dash use \u2013, as in "high\u2013low".

Peter

Translate
Community Expert ,
Nov 24, 2012 Nov 24, 2012

Add some text to a text frame:

tframe.parentStory.insertionPoints[-1].contents = " appended text"

For an em-dash use \u2013, as in "high\u2013low".

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
Community Expert ,
Nov 24, 2012 Nov 24, 2012

Hi Peter,

Your solution worked thanks, but i have some confusion i was trying with the code as

pi.insertionPoints.lastItem().contents = "appended text"

this code was working fine unless i tried to append text in a threaded textframe. In some cases the text was jumbled up depending upon where it was inserted, in some cases some portion of text was inserted in reverse order. Could you explain what was wrong in this code, also what does -1 index in your code stand for.

It will be very nice and helpful of you if you could clear up my confusion.

Thanks

-Manan

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 ,
Nov 25, 2012 Nov 25, 2012

Manan,

Why the text you insert was garbled or inserted in reverse order I don't know. I don't see that, even in threaded frames.

insertionPoints[-1] is the equivalent of insertionPoints.lastItem() but it's less typing. On the whole you'd better avoid things like nextItem(), previousItem(), which are terribly slow in longer stories. I don't know about firstItem() and lastItem(), they may not be slower than their equivalents [0] and [-1], but the latter as simply easier to type.

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
Community Expert ,
Nov 25, 2012 Nov 25, 2012
LATEST

Text may get inserted in reverse if you add to *frames* instead of to the story, because any new text you add may get pushed immediately to the next frame.

If you want to add text to the "end of a frame", either do so in one chunk, or assemble it into a temporary text frame and when done, move it into a single chunk. But there is nothing you can do to ensure it actually *appears* at the "end of a frame"; if it's full, the text will flow into the next one or get overset.

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