6 Replies Latest reply on Jul 1, 2015 2:02 AM by Sudha K

    Remove unused Styles using actions

    Sudha K Level 1

      Hi,

       

         I need to delete unused paragraph styles in document using action, until selection of unused style count is 0. 

         I saw  the below url in this forum.  Can i do this using action???

       

      remove unused styles in one action...

       

      Thanks in advance,

      Sudha K

        • 1. Re: Remove unused Styles using actions
          Math Kay Level 1

          Hi,

           

          Please use this script. It might be helpful to you.

           

          var myDoc = app.activeDocument; 
          var myParStyles = myDoc.paragraphStyles; 
          var myCharStyles = myDoc.characterStyles; 
          for (i = myParStyles.length-1; i >= 2; i-- ){ 
             removeUnusedParaStyle(myParStyles[i]) 
          for (i = myCharStyles.length-1; i >= 1; i-- ){ 
             removeUnusedCharStyle(myCharStyles[i]) 
          function removeUnusedParaStyle(myPaStyle) { 
             app.findTextPreferences = app.changeTextPreferences=null;
             app.findTextPreferences.appliedParagraphStyle = myPaStyle; 
             var myFoundStyles = myDoc.findText(); 
                if (myFoundStyles == 0) { 
                   myPaStyle.remove(); 
               
             app.findTextPreferences = app.changeTextPreferences=null;   
          function removeUnusedCharStyle(myChStyle) { 
             app.findTextPreferences = app.changeTextPreferences=null;
             app.findTextPreferences.appliedCharacterStyle = myChStyle; 
             var myFoundStyles = myDoc.findText(); 
                if (myFoundStyles == 0) { 
                   myChStyle.remove(); 
               
             app.findTextPreferences = app.changeTextPreferences=null; 

           

          alert(" All Unused Styles removed Successfully");

          • 2. Re: Remove unused Styles using actions
            Sudha K Level 1

            Hi,

             

            Thank you... Can we do this using menu action??

            I can remove styles using menu action using the below code.

             

            try{

            app.menuActions.itemByID(8474).invoke();

            app.menuActions.itemByID(8451).invoke();

            }catch(e){

            app.menuActions.itemByID(8450).invoke();

            app.menuActions.itemByID(8474).invoke();

            app.menuActions.itemByID(8451).invoke();

            }

             

            But my prob is the dialog box appeared when run the code. How can i escape that dialog without mapping style??

             

            Screen shot 2015-06-29 at 9.51.13 AM.png

             

             

            - Sudha K

            • 3. Re: Remove unused Styles using actions
              Math Kay Level 1

              Hi,

              if Unused style is "based on" to another style, it will ask replace any style with unused style. Please find the style in which the "based on" style(unused) has been used and redefine it. Then you can run script. It will not show the dialog to replace any style. I hope this will work.

               

              Thanks

              K Ramesh

              • 4. Re: Remove unused Styles using actions
                Sudha K Level 1

                Hi,

                 

                Thank you. yes its working now.

                 

                If i change based on to "[No Paragraph Style]" and Next style to "[Basic Paragraph]", will it make any changes in document???

                 

                - Sudha K

                • 5. Re: Remove unused Styles using actions
                  Math Kay Level 1

                  Hi,

                  It will not make any change. However, please create pdf and compare with old one to check this. If my answer is correct, please mark it as correct answer so that it will be reference to others.

                   

                  Thanks

                  K Ramesh

                  • 6. Re: Remove unused Styles using actions
                    Sudha K Level 1

                    Hi,

                     

                      Thank you...