5 Replies Latest reply on Aug 31, 2018 7:15 AM by Laubender

    How to get Used Paragraph and Character Styles List?

    Senthilvel S

      Hi All,

       

      How do we get Used Paragraph and Character Styles List? I am using below code for find used paragraph styles. But it takes more time for large and complex documents.

       

      app.findTextPreferences.appliedParagraphStyle = myParaStyle; 

      var arr_FindParaStyles = g_Doc.findText(); 

      if (arr_FindParaStyles.length  != 0)

      return true;

      }

       

      Is there any other way to get this list?

       

      Thanks & Regards,

      Senthilvel S

        • 1. Re: How to get Used Paragraph and Character Styles List?
          Manan Joshi Level 4

          You could reduce the scope of the find like searching each story or text frame rather than the whole document. That could speed up the process, as it would have to find less amount of data, if not found only then you move ahead to the next story or text frame for a particular paragraph or character style.

           

          -Manan

          • 2. Re: How to get Used Paragraph and Character Styles List?
            Laubender Adobe Community Professional & MVP

            Hi Senthilvel S,

            If you don't mind using menu commands you could do:

             

            // "Select All Unused" in the Paragraph Styles Panel:
            app.menuActions.itemByID(8474).invoke();
            
            // "Delete Styles" in the Paragraph Styles Panel:
            app.menuActions.itemByID(8451).invoke();
            
            // All used then are:
            var allUsedParaStyles = app.documents[0].allParagraphStyles;
            
            // Listing the ones in the JavaScript Console of the ESTK:
            for( var n=0; n<allUsedParaStyles.length; n++ )
            {
                $.writeln( n +"\t"+ allUsedParaStyles[n].id +"\t"+ allUsedParaStyles[n].name );
            };
            
            // Then close the document without saving or undo the last action like here:
            app.documents[0].undo();
            

             

            Important Note:
            With that script snippet you cannot tell if paragraphStyles[1] named "$ID/NormalParagraphStyle" is used.

             

            Regards,
            Uwe

            • 3. Re: How to get Used Paragraph and Character Styles List?
              Laubender Adobe Community Professional & MVP

              Also consider:

              If you detect paragraph styles by looking at the text, so you detect the ones that are applied to the text only.

              You will not find the ones that other styles are based on. You cannot e.g. remove the "unused" ones without changing the other ones, the applied ones ( if you have that in mind at all ).

               

              What do you like to do with the unused styles?

               

              Regards,
              Uwe

               

              EDITED

              • 4. Re: How to get Used Paragraph and Character Styles List?
                Senthilvel S Level 1

                Hi Laubender,

                 

                Thanks for your response. But I don't want to delete the Unused styles, because we may use that unused styles in revises stage. Instead of delete, is there any other way to store that unused style names in the text file.

                 

                Thanks & Regards,

                Senthilvel S

                • 5. Re: How to get Used Paragraph and Character Styles List?
                  Laubender Adobe Community Professional & MVP

                  Hi Senthilvel S,

                  with my suggestion you delete the unused ones only temporarily.

                  Just get the allParagraphStyles and allCharacterStyles array before and after removing the unused styles.

                  Then undo or close the document without saving and open it again.

                   

                  You could extract the id numbers of the styles in a first step from the arrays.

                  And you can extract the id numbers in the second step from the array after removing the unused styles.

                  Compare the two arrays to get a list of the unused ones.

                   

                  In a report note the id numbers together with the names, because one could have two or more styles with the same name, if the styles are located in different style groups.

                   

                  Regards,
                  Uwe