5 Replies Latest reply on Apr 9, 2009 3:50 AM by AdobeScripts

    Add Formatted Text

      Hello,

      I am trying to create a series of scripts to be used in a template that add/insert formatted text at a cursors location. So far, I have created the following script:

      app.selection[0].paragraphs[0].insertionPoints[0].contents = 'Voiceover'

      This works just fine, but how do I get this text to automatically select a Paragragh style I have defined.

      Thanks!
        • 1. Re: Add Formatted Text
          Level 1
          app.selection[0].paragraphs[0].appliedParagraphStyle = myStyle;

          where myStyle is a reference to the paragraph style.

          Dave
          • 2. Re: Add Formatted Text
            Level 1
            Excellent. I now have a follow-up question. How can I add a new line of text? For example, the above script writes "Voiceover" in BigRed paragraph style. Now I want to add a new line under "Voiceover" that says "Line 2" in a different paragraph style. This is what I have come up with:

            app.selection[0].paragraphs[0].insertionPoints[0].contents = 'Voiceover'
            app.selection[0].paragraphs[0].appliedParagraphStyle = 'BigRed'
            app.selection[0].paragraphs[0].insertionPoints[10].contents = 'Line 2'
            app.selection[0].paragraphs[0].appliedParagraphStyle = 'BigRed2'

            Thanks Again!
            • 3. Re: Add Formatted Text
              Level 1
              add "\r" at end of your text contents or as a single character

              app.selection[0].paragraphs[0].insertionPoints[-1].contents = 'Voiceover\r'

              or

              app.selection[0].paragraphs[0].insertionPoints[-1].contents = '\r'

              if you are building new text in new empty Story or at end of current Story - don't use absolute index - .insertionPoints[10] - use .insertionPoints[-1] as reference to last item

              app.selection[0].paragraphs[-1].insertionPoints[-1].contents = '\r'
              (you need to add this line if you want to start new paragraph after existing text)

              app.selection[0].paragraphs[-1].appliedParagraphStyle = 'BigRed'
              app.selection[0].paragraphs[-1].insertionPoints[-1].contents = 'Voiceover\r'
              app.selection[0].paragraphs[-1].appliedParagraphStyle = 'BigRed2'
              app.selection[0].paragraphs[-1].insertionPoints[-1].contents = 'Line 2\r'

              like you can see - you need to switch order of lines - first you need to set formatting (ParaStyle) - then set new contents - and this is the best order of operations

              step 1 - set formatting to LastInsertionPoint
              step 2 - set contents of LastInsertionPoint

              thanks to this - you don't need to care how long will be your new text ;)


              if you want to add new text to empty TextFrame - you can't refer to first paragraph - because there is no paragraphs in empty TextFrame - you need to refer to insertionPoint - and better - to last insertionPoint of parentStory

              app.selection[0].parentStory.insertionPoints[-1]

              robin

              --
              www.adobescripts.com
              • 4. Re: Add Formatted Text
                Tony Tuneson Level 1

                If processing speed is not highest priority, you could consider to create a "Tagged Text" file first, and then use the "Place" command to insert it at the insertionpoint.

                If you don't know how "Tagged Text" looks, just export a formatted piece of text and open it in a (Unicode) text editor.

                • 5. Re: Add Formatted Text
                  AdobeScripts Level 3

                  Tony Tuneson wrote:

                   

                  If processing speed is not highest priority, you could consider to create a "Tagged Text" file first, and then use the "Place" command to insert it at the insertionpoint.

                   

                  but TaggedText is fastest way to prepare long texts

                   

                  robin

                   

                  --

                  www.adobescripts.co.uk