3 Replies Latest reply on Oct 23, 2013 7:45 AM by Dan-BTP

    Individual paragraph styling

    Dan-BTP Level 1

      In a loop, I am inserting a number of paragraphs into a text frame. Here is part of the code:

       

      paragraph = story.paragraphs.lastItem();

      paragraph.applyParagraphStyle(myDoc.paragraphStyles.item("Poem"), false);

       

      with (paragraph.appliedParagraphStyle) {

          leading = "10.5pt";

          pointSize = "10.0pt";

          }

       

      In the paragraph styles catalog for the document, there is a style defined called "Poem". For each paragraph inserted into the text frame, I want it to have all the properties of the catalog style "Poem" except that I want to change its point size and leading. Shown above I have hard-coded them to be "10.5pt" and "10.0pt" respectively, but in actual fact there are different values for each paragraph. I don't want the paragraphs to get their point size and leading from the paragraph styles catalog.

       

      The above code is not working. How should I be applying individual paragraph styling that is different from the paragraph styles catalog?

       

      Thanks!

        • 1. Re: Individual paragraph styling
          BEGINNER_X Level 3

          Hi Dan,

           

          Please use this below code, may it will be helpful;

           

           

          var myDoc = app.activeDocument;
          
          app.findTextPreferences = app.changeTextPreferences = null;
          
          app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; 
          app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
          
          try
          {
          app.findTextPreferences.appliedParagraphStyle = "POEM"
          }
          catch(e)
          {
              alert("POEM style does not exit")
              exit(0);
              }
          
          var myFound = myDoc.findText()
          
          //~ alert(myFound.length);
          
          
          for(i=myFound.length-1; i>=0; i--)
          {
              myFound[i].leading = "10.5"
              myFound[i].pointSize = "10"
              }
          

           

          Thanks

          Beginner_X

          • 2. Re: Individual paragraph styling
            Jump_Over Level 5

            Hi,

             

            1st at all - you can modify "pointSize" and "leading" property of various text objects

            (i.e. word, line, paragraph, paragraphStyle) but modifying paragraphStyle you modify every part of text where this style is applied at the same time.

             

            So the solution is to modify paragraph.leading instead of paragraph.appliedParagraphStyle.leading

             

            2nd - you could use Find...Change utility to reach a goal, since last paragraph of story is reached when you fill

            .+\Z into Find Grep field.


            (change particular format properties in Grep "ChangeTo" part of dialog.)

             

            Jarek

            • 3. Re: Individual paragraph styling
              Dan-BTP Level 1

              Jarek,

               

              Thanks! That was the solution I needed.

               

              Dan