6 Replies Latest reply on Oct 13, 2010 4:38 AM by tansk02

    Help!  InDesign CS4 Unused Paragraph Styles Alert message

    tansk02

      Below is the script that I have download from Adobe Forum.

      This script deletes all the unused paragraphstyles from active document in InDesign CS4.

       

      I want to modify this script to show only alert message for unused style and save report as a text file.
      I don't want to remove my unused style from my active document.

       

       

      Please help.

       

       

       

       

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

        • 1. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
          sandy_88 Level 1

          I think this will help you

           

          var myDoc = app.activeDocument;
          var myParStyles = myDoc.paragraphStyles;
          var myCharStyles = myDoc.characterStyles;
          for (j = myParStyles.length-1; j >= 2; j-- ) {
          removeUnusedParaStyle(myParStyles[j]);
          }
          for (i = myCharStyles.length-1; i >= 1; i-- ){
          removeUnusedCharStyle(myCharStyles[i]);
          }
          function removeUnusedParaStyle(myPaStyle) {
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          app.findTextPreferences.appliedParagraphStyle = myPaStyle;
          var myFoundStyles = myDoc.findText();

          if (myFoundStyles == 0) {
          alert(myPaStyle.name);
          write(myPaStyle.name);
          }
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          }


          function removeUnusedCharStyle(myChStyle) {
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          app.findTextPreferences.appliedCharacterStyle = myChStyle;
          var myFoundStyles = myDoc.findText();

          if (myFoundStyles == 0) {
          alert(myChStyle.name);
          write(myChStyle.name);
          }
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          }


          function write(text){
            var myDocument=app.activeDocument;
          //  var myFileName1=document.name;
            var myFilePath1=myDocument.filePath + "/" + "Unused Paragraph and Character Style" + ".txt";
            var myTextFile = new File(myFilePath1);
             if ( myTextFile.exists )
             {
             myTextFile.open("e");
             myTextFile.seek(0, 2);
              
             }
             else {
             myTextFile.open("w");
             }
            myTextFile.write(text);

          }

           

          Sajeev

          1 person found this helpful
          • 2. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
            tansk02 Level 1

            Hi,

             

            Thanks for your reply. It helps to show only single paragraph style on alert box.

             

            But if I have changed the code write(myPaStyle.name) to $.writeln(myPaStyle.name) then it shows unused style one by one on alert message.

             

            Is anybody know how to save this message into text file in computer?

             

            And also how to show all unused styles together on alert dialog message.

             

            Please let me know.

            • 3. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
              Marijan Tompa [tomaxxi] Level 4

              Hey!

               

              Try this:

               

              var myDoc = app.activeDocument;
              var myParStyles = myDoc.paragraphStyles;
              var myCharStyles = myDoc.characterStyles;
              var foundPStyles = [];
              var foundCStyles = [];
              for (j = myParStyles.length-1; j >= 2; j-- ) {
                  foundPStyles.push(removeUnusedParaStyle(myParStyles[j]));
              }
              for (i = myCharStyles.length-1; i >= 1; i-- ){
                  foundCStyles.push(removeUnusedCharStyle(myCharStyles[i]));
              }

              alert(foundPStyles.join("\r"));
              alert(foundCStyles.join("\r"));

              function removeUnusedParaStyle(myPaStyle) {
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing;
                  app.findTextPreferences.appliedParagraphStyle = myPaStyle;
                  var myFoundStyles = myDoc.findText();
                      if (myFoundStyles == 0) {
                          return myPaStyle.name;
                      }
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing;
              }


              function removeUnusedCharStyle(myChStyle) {
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing;
                  app.findTextPreferences.appliedCharacterStyle = myChStyle;
                  var myFoundStyles = myDoc.findText();
                      if (myFoundStyles == 0) {
                          return myChStyle.name;
                      }
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing;
              }

               

              --

              tomaxxi

              http://indisnip.wordpress.com/

              1 person found this helpful
              • 4. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
                tansk02 Level 1

                Thanks for your answer.

                 

                It shows all the unused style on one dialog.

                 

                Could you please help me to guide me to achieve following task through this script:

                 

                1. How to save alert message warinings (unused paragraph styles) as a text file in computer.

                2. If there is no unused style in my document then it shows alert message "There is no unused paragraph in this document" else show "There are following ungroupd styles in this documents".

                 

                Thanks in advance.

                • 5. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
                  PankChat Level 1

                  1. How to save alert message warnings (unused paragraph styles) as a text

                  file in computer.

                  2. If there is no unused style in my document then it shows alert message

                  "There is no unused paragraph in this document" else show "There are

                  following ungroupd styles in this documents".

                   

                  I am not sure about point 2 but I think what Sajeev has provided you (not

                  tested) in earlier post does the same (means writing to text file saved in

                  same location).

                  • 6. Re: Help!  InDesign CS4 Unused Paragraph Styles Alert message
                    tansk02 Level 1

                    Thanks Sanjeev,

                     

                    This is working as I needed.

                     

                    Thanks a lot.