2 Replies Latest reply on May 19, 2010 9:55 PM by SB Masthan

    JS: Grep in style names

    SB Masthan Level 1

      Dear All,

       

      Is there any way to gather/find paragraph styles with some conditions? For Example: Gather paragraph style names which are starting with the character "H" in an array (like "H1", "H2", "Head", etc).

       

      Kindly let me know the basic coding for this.

       

      Thanks in advance.

       

      regards

      Masthan

        • 1. Re: JS: Grep in style names
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          It's really easy to get...

           

          var myDoc = app.activeDocument;
          var myStyles = myDoc.paragraphStyles;
          var foundStyles = Array();
          var searchString = String("H"); //you can enter more than one startng letter
          var tempName = String();
          for(i=1;myStyles.length > i;i++){
              tempName = myStyles[i].name;
              if(tempName.substr (0, searchString.length) == searchString){
                  foundStyles.push (tempName);
              }
          }

           

          //List found styles
          var nameList = String("/ ");
          for(i=0;foundStyles.length>i;i++){
              nameList += foundStyles[i] + " / ";
          }
          alert(nameList);

           

          tomaxxi

          • 2. Re: JS: Grep in style names
            SB Masthan Level 1

            Hi Tomaxxi,

             

            Thanks a lot... Its works fine.

             

            regards

            Masthan