1 Reply Latest reply on Dec 16, 2013 8:02 PM by Mi_D

    Remove unused styles at the book level.

    tmkister Level 1

      We have hundreds of legacy ID documents that have been created over the last 15 years, and the styles are messy and confusing. We need to change the syle names and update the styles. Doing this for each document will be a nightmare, as ID adds styles when synchronizing books, but does not remove unused styles.

       

      Does anyone know of a script that can be used to remove unused styles at the book level?

       

      I originally wondered if this can be done for paragraph styles, but it has since occurred to me that it would be great if we could do this for all types of styles.

       

      FYI, I don't know anything about writing scripts and almost nothing about how they work – I'm looking for a script that already exists. This is for use by a business, so purchasing the script is an option.

       

      We use ID CS6, Windows 7.

       

      Thank you!

        • 1. Re: Remove unused styles at the book level.
          Mi_D Level 3

          try below code

          var myFolder = new Folder('E:\\Book\\'); //Folder path

          var files = myFolder.getFiles("*.indb");

          for(i = 0; i < files.length; i++)

              {

                 var theDocument = app.open(File(files[i]), true);

                   with ( theDocument ) {

                      removeStyle(theDocument);

                          }

             }

           

          function removeStyle(theDocument)

          {

          var bookComps = app.books[0].bookContents

              for (var b = 0; bookComps.length > b; b++)

              {

                 var myDoc = app.open(bookComps[b].fullName);

                 var myParStyles = myDoc.paragraphStyles;

                 var myCharStyles = myDoc.characterStyles;

                    for (p = myParStyles.length-1; p >= 2; p-- )

                    {

                         removeUnusedParaStyle(myParStyles[p], myDoc);

                     }

                      for (c = myCharStyles.length-1; c >= 1; c-- )

                      {

                          removeUnusedCharStyle(myCharStyles[c], myDoc);

                      }

                 myDoc.close(SaveOptions.yes);

              }

          }

          function removeUnusedParaStyle(myPaStyle, myDoc) {

          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, myDoc) {

          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;

          }

           

          Mi_D