Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Remove unused objectStyle

Return to Member Forum

  • Author
    Posts
    • #92272
      Kathy Cote
      Member

      I have a script to remove all unused swatch and paragraph styles.
      Is it possible to remove all unused Object Styles too?

      Thank you for your help. It is always appreciated

      ////////////////

      while (app.documents.length) {
      var myDocument = app.activeDocument;

      //Swatchs
      var myUnusedSwatches = myDocument.unusedSwatches;
      for (var s = myUnusedSwatches.length-1; s >= 0; s–) {
      var mySwatch = myDocument.unusedSwatches[s];
      var name = mySwatch.name;
      // alert (name);
      if (name != “”){
      mySwatch.remove();
      }
      }

      //Layers
      var layers = app.activeDocument.layers.everyItem().getElements();
      for(var i=layers.length-1;i>=0;i–){
      if(layers[i].pageItems.length==0){
      layers[i].remove();
      }
      }

      //Styles
      var myParStyles = myDocument.paragraphStyles;
      var myCharStyles = myDocument.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 = myDocument.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 = myDocument.findText();
      if (myFoundStyles == 0) {
      myChStyle.remove();
      }
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      }

      myDocument.close(SaveOptions.YES);

      }

    • #92301
      Andre Vandal
      Member
    • #92385
      Kathy Cote
      Member

      ok good, it works.

      Thanks for your help

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads