9 Replies Latest reply on Oct 15, 2015 2:26 AM by devsel

    Remove Unused Paragraph Styles - without basedOn styles

    devsel

      Hi All,

      I have deleting the Unused paragraph style, re-flow the content reason for "basedOn" style also deleted.

       

      How is avoid to deleting basedOn styles.

       

      Example here:

      1. I haven't used the "06 Extract" paragraph style directly in to the paragraphs (texts), so this is unused paragraph style.

      2. I have applied "06 Extract 1P" paragraph style directly to the paragraphs (texts), but connected the "06 Extract" pstyle to indirectly "06 Extract 1P"(with the basedOn option) see below.

       

      While deleting the unused styles, the "06 Extract" also deleted and affect to "06 Extract 1P". So, re-flow occurring in this document, how to avoid this? No need to remove the using 'basedOn' styles (example: "06 Extract").

       

       

       

      Screen shot 2015-10-12 at 3.27.12 PM.png

       

       

       

          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 >= 2; 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; 

          } 

       

       

      Advance thanks,

      Dev