6 Replies Latest reply on Jun 6, 2018 8:47 AM by manuelb27477138

    Get length of Paragraph Style Names

    manuelb27477138 Level 1

      Hello!

       

      I have many Paragraph Styles with the same name like this:

      Book Cover Page 1
      Book Cover Page 2
      Book Cover Page 3
      Book Cover Page 4
      Book Cover Page 5
      Book Cover Page 6
      Book Cover Page 7
      Book Cover Page 8
      Book Cover Page 9
      Book Cover Page 10
      ....
      Book Cover Page 99
      Book Cover Page 100
      

       

       

      How can I get the length, for create a loop for and replace the number 100 for something like paragraph.name"Book Cover Page".lenght

      for(i=0;i<100;i++){
      if(myParas[i].appliedParagraphStyle.name == "Book Cover Page "+[i]){
      myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-Book Cover Page");}}
      

       

       

       

      Thanks so much!

       

        • 1. Re: Get length of Paragraph Style Names
          yadavs92328 Level 2

          Hi there,

               You can try the below code,

          var myDoc = app.documents[0];
          var allParaStyleWithSameName = [];
          var counter = 0;
          while(counter < myDoc.paragraphStyles.length){
              if(myDoc.paragraphStyles[counter].name.toString().indexOf('book cover page') != -1){
                  //You can do something here//
                  allParaStyleWithSameName.push(myDoc.paragraphStyles[counter]);
                  }
              counter++;
              }
          alert(allParaStyleWithSameName.length);
          //You can do something here looping through your array//
          
          1 person found this helpful
          • 2. Re: Get length of Paragraph Style Names
            Laubender Adobe Community Professional & MVP

            Hi Manuel,

            you can write all paragraph styles, also the ones in style groups, to an array with:

             

            var allParaStyles = app.documents[0].allParagraphStyles;
            var allParaStylesLength = allParaStyles.length;
            

             

            Regards,
            Uwe

            1 person found this helpful
            • 3. Re: Get length of Paragraph Style Names
              manuelb27477138 Level 1

              Hi yadav!

              Is working when the styles are in the first level of styles,  but my styles are in a folder, like you can see:

               

              Screen Shot 2018-06-04 at 11.20.02.png

               

              Screen Shot 2018-06-04 at 11.23.59.png

               

              How can I add the folder BOOK COVER PAGE into the script?

              I try this but didn't work:

              var myDoc = app.documents[0];  
              var allParaStyleWithSameName = [];  
              var counter = 0;  
              while(counter < myDoc.paragraphStyles.length){  
                  if(myDoc.paragraphStyleGroups.itemByName("BOOK COVER PAGE").paragraphStyles[counter].name.toString().indexOf('Book Cover Page ') != -1){  
                      //You can do something here//  
                      allParaStyleWithSameName.push(myDoc.paragraphStyleGroups.itemByName("BOOK COVER PAGE").paragraphStyles[counter]);  
                      }  
                  counter++;  
                  }  
              alert(allParaStyleWithSameName.length);  
              //You can do something here looping through your array//  
              

               

               

              Thanks!

              • 4. Re: Get length of Paragraph Style Names
                manuelb27477138 Level 1

                Why don't work?

                I added the Style group:

                 

                var myDoc = app.documents[0];  
                var allParaStyleWithSameName = [];  
                var counter = 0;  
                var pStyleGroup = myDoc.paragraphStyleGroups.itemByName('BOOK COVER PAGE');
                while(counter < myDoc.pStyleGroup.paragraphStyles.length){  
                    if(myDoc.pStyleGroup.paragraphStyles[counter].name.toString().indexOf('Book Cover Page ') != -1){  
                        //You can do something here//  
                        allParaStyleWithSameName.push(myDoc.pStyleGroup.paragraphStyles[counter]);  
                        }  
                    counter++;  
                    }  
                alert(allParaStyleWithSameName.length);  
                

                 

                Please help me.

                Thanks so much.

                • 5. Re: Get length of Paragraph Style Names
                  Ananth@desgin Level 3

                  Hi,

                  I hope this will help you.

                   

                  var myDoc = app.documents[0];    
                  var allParaStyleWithSameName = [];   
                  
                  
                  var counter = 0;   
                  
                  var pStyleGroup = myDoc.paragraphStyleGroups.itemByName("BOOK COVER PAGE");
                  
                  
                  while(counter < pStyleGroup.paragraphStyles.length){    
                  if(pStyleGroup.paragraphStyles[counter].name.toString().indexOf("Book Cover Page") != -1){    
                          //You can do something here//    
                       allParaStyleWithSameName.push(pStyleGroup.paragraphStyles[counter]);    
                         }    
                      counter++;    
                      }    
                  alert(allParaStyleWithSameName.length);
                  

                   

                   

                  Thanks,

                  Prabu G

                  • 6. Re: Get length of Paragraph Style Names
                    manuelb27477138 Level 1

                    Hi Prabu!

                    is working fantastic!

                    I really appreciate your help.