1 Reply Latest reply on Jul 30, 2010 5:00 AM by [Jongware]

    Applying styles to a text in textframe

    Anitha Selvaraj

      Hi All,


      For applying styles to a text in a textframe, I am writing the following script. Is this an optimal way? Or Is there any other single line command or something which applies styles to all the characters in the textframe.


      var textLength= textFrame.parentStory.paragraphs.length;

      for(var l = 0; l< textLength ; l++){
          var myTextObject =
      textFrame.parentStory.paragraphs.item(l);
              myTextObject.strokeWeight = 3;
              myTextObject.pointSize = 6;
              myTextObject.justification = Justification.RIGHT_ALIGN;
      }   


      As you can see, i have applied styles for each character in the textframe.


      Please guide me the correct solution.


      Thanks,

      Anitha                                                                

                                                                             

               

       

        • 1. Re: Applying styles to a text in textframe
          [Jongware] Most Valuable Participant

          mmm ... I thought it was possible to assign text attributes to entire text frames, but that doesn't seem to work. Perhaps I remembered it wrong.

           

          For any text frame you can directly access its paragraphs, there is no need to go "up" to parentStory then "down" again. This is even crucial when you want it to work on threaded text frames, because it would change the first paragraphs of the story, not of the current selected frame.

           

          However: there is another way to change text properties, if (and only if) you want them applied to every text inside an object. For that, you can use the text frame property "Texts" (an array, although, as far as I know, it always has one single item).

          A further improvement is you can assign various properties in one go by creating a custom object and setting that though "properties":

           

          textframe.texts[0].properties = { strokeWeight:3, pointSize:6, justification:Justification.RIGHT_ALIGN };

           

          This works because the 'properties' of Text are, by design, the same as those of Paragraph. You only need to address individual paragraphs if you want to assign different properties to each.