Skip to main content
December 16, 2013
Question

Remove unused styles at the book level.

  • December 16, 2013
  • 1 reply
  • 475 views

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!

This topic has been closed for replies.

1 reply

Inspiring
December 17, 2013

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), 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.fullName);

       var myParStyles = myDoc.paragraphStyles;

       var myCharStyles = myDoc.characterStyles;

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

          {

               removeUnusedParaStyle(myParStyles

, myDoc);

           }

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

            {

                removeUnusedCharStyle(myCharStyles, 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