4 Replies Latest reply on Nov 25, 2012 3:27 AM by [Jongware]

    Adding content to a textframe

    Manan Joshi Level 4

      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.



        • 1. Re: Adding content to a textframe
          Peter Kahrel Adobe Community Professional & MVP

          Add some text to a text frame:


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


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



          • 2. Re: Adding content to a textframe
            Manan Joshi Level 4

            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.




            • 3. Re: Adding content to a textframe
              Peter Kahrel Adobe Community Professional & MVP



              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.



              • 4. Re: Adding content to a textframe
                [Jongware] Most Valuable Participant

                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.