10 Replies Latest reply on Jun 3, 2014 1:35 AM by Chinnadk

    Auto create paragraph styles and properties

    ASHOK KUMAR Level 1

       

      Dear All

       

      I had created Two paragraph styles using with below script. Now I have set in H1 All properties (like Basic Character Formats (font, font size, leading, tracking, kerning, Indent and spacing, Tabs, Paragraph rules, Keep option and all of paragraph style Options). It is possible to fix. Totally I will have creat 60 to 70 styles.

       

      Thanks in advance

       

       

      The code is:

       

      var doc = app.activeDocument;

      var array = ["H1", "H2"];

      for(var i=0;i<array.length;i++)

      {

          try{

              doc.paragraphStyles.add({name:array[i]});

              }

          catch(e)

          {

                      alert("'" + array[i] + "'" + "already exists in the document.")

              }

          }

       

       

       

      Thanks

      ASHRAM

        • 1. Re: Auto create paragraph styles and properties
          Chinnadk Level 4

          Hi Ashram,

           

          Try this.

           

          var doc = app.activeDocument;

          var array = ["H1", "H2"];

          for(var i=0;i<array.length;i++)

          {

              try{

                  var pstyle = doc.paragraphStyles.add({name:array[i]});

                  with(pstyle) //Change the below lines as per your requirement

                  {

                          appliedFont = "Arial";

                          pointSize = 12;

                          leading = 15;

                          tracking  = 100

                          ....

                      }

                  }

              catch(e)

              {

                          alert("'" + array[i] + "'" + "already exists in the document.")

                  }

              }

          • 2. Re: Auto create paragraph styles and properties
            ASHOK KUMAR Level 1

            Hi Chinna

             

            Thanks for your code.

             

            Now It's working fine. But I will have creat 60 to 70 styles in different fonts and size, leading etc...

             

            Each styles I will have create separate code?

             

            Thanks

            ASHRAM

            • 3. Re: Auto create paragraph styles and properties
              ASHOK KUMAR Level 1

              Hi Chinna

               

              I like set Paragraph properties near in particular style.

               

              like:

              var array = ["H1, font:______, font style: _______, tracking______, leading_____ etc", "H2, font:______, font style: _______, tracking______, leading_____ etc"];

               

              It is possible Chinna?

               

              Thanks

              ASHRAM

              • 4. Re: Auto create paragraph styles and properties
                Chinnadk Level 4

                Try this.

                 

                var doc = app.activeDocument;

                var array = ["H1", "H2"];

                for(var i=0;i<array.length;i++)

                {

                    try{

                          if(array[i] == "H1"){

                              doc.paragraphStyles.add({name:array[i], appliedFont:"Arial", pointSize:12, leading:15});

                            }

                          if(array[i] == "H2"){

                              doc.paragraphStyles.add({name:array[i]}, appliedFont:"Minion", pointSize:10, leading:12);

                            }

                        }

                    catch(e)

                    {

                                alert("'" + array[i] + "'" + "already exists in the document.")

                        }

                    }

                 

                Regards,

                Chinna

                • 5. Re: Auto create paragraph styles and properties
                  ASHOK KUMAR Level 1

                  Hi Chinna

                   

                  It is OK . But H1 and H2 applied in Same font style, size and leading.

                   

                  This style have been different font size, font style, leading, color and etc..

                   

                  Example :

                   

                  H1 = appliedFont:"Arial", pointSize:12, leading:15 . . . .

                  H2 = appliedFont:"Times", pointSize:10, leading:13 . . . .

                  H3 = Different font, font style, point size, leading .....

                  H4 = Different font, font style, point size, leading .....

                  Bull list = Different font, font style, point size, leading .....

                  Num list = Different font, font style, point size, leading .....

                  etc.

                   

                  Totally in 60 to 70 styles.

                   

                  How to fix other styles ?

                   

                  Thanks

                  ASHRAM

                  • 6. Re: Auto create paragraph styles and properties
                    Chinnadk Level 4

                    Hi ASHRAM,

                     

                    It is working fine here. Just try again.

                     

                    var doc = app.activeDocument;

                    var array = ["H1", "H2"];

                    for(var i=0;i<array.length;i++)

                    {

                        try{

                              if(array[i] == "H1"){

                                  doc.paragraphStyles.add({name:array[i], appliedFont:"Arial", pointSize:12, leading:15});

                                }

                              if(array[i] == "H2"){

                                  doc.paragraphStyles.add({name:array[i], appliedFont:"Minion", pointSize:10, leading:12});

                                }

                            }

                        catch(e)

                        {

                                    alert("'" + array[i] + "'" + "already exists in the document.")

                            }

                        }

                     

                    Regards,

                    Chinna

                    • 7. Re: Auto create paragraph styles and properties
                      ASHOK KUMAR Level 1

                      Hi Chinna

                       

                      I did use above code the following error was found.

                      Untitled.png

                       

                      After I check and use below code. It's working fine chinna.

                       

                      var doc = app.activeDocument;

                      var array = ["H1", "H2"];

                      for(var i=0;i<array.length;i++)

                      {

                          try{

                                if(array[i] == "H1"){

                                    doc.paragraphStyles.add({name:array[i], appliedFont:"Arial", pointSize:12, leading:15});

                                  }

                                if(array[i] == "H2"){

                                    doc.paragraphStyles.add({name:array[i], appliedFont:"Minion", pointSize:10, leading:12});

                                  }

                              }

                          catch(e)

                          {

                                      alert("'" + array[i] + "'" + "already exists in the document.")

                              }

                          }

                       

                      It is OK Chinna...?

                       

                       

                      Thanks

                      ASHRAM

                      • 8. Re: Auto create paragraph styles and properties
                        ASHOK KUMAR Level 1

                        Hi Chinna

                         

                        Thanks for your effort ... Thanks

                         

                         

                        Thanks

                        ASHRAM

                        • 9. Re: Auto create paragraph styles and properties
                          ASHOK KUMAR Level 1

                          Hi Chinna

                           

                          How to code Paragraph style Options all properties.

                           

                          Example:

                           

                          appliedFont = "Arial";

                          pointSize = 12;

                          leading = 15;

                          tracking  = 100

                          spaceAbove = "10mm";

                          spaceBelow = "10mm";

                           

                          etc.....

                           

                          Thanks

                          ASHRAM