2 Replies Latest reply on Mar 21, 2013 4:24 AM by Peter Spier

    Please help me!!

    Bhatt, Manish Level 1

      Hi All

       

      I have create a new script Deleted unused paragraph, unused charaterstyle and unused swatches but they have not run in batch please check my script and update me what is incorrect on this script please help me

       

       

      //Create by Manish Bhatt (DMD)

      try{

                 // Ask for the input and output folder (or hardcode define them if you want)

                 inFolderName= Folder.selectDialog ("Input Folder:");

                 // inFolderName = "/ID Files";

       

                 if (inFolderName != null )

                 {

                  var idFileFolder = new Folder(inFolderName);

                  // If you need the script to create the folder, do this

                  //var expFileFolder = new Folder(outFolderName);

                  //expFileFolder.create();

                  var dir;

                  dir = idFileFolder.getFiles();

                  //for each sub folder

      for(i=0;i<=dir.length-1;i++)

                 {

                  var idFileFolder1=new Folder(dir[i]);

                  // get the list of files that are InDesign files

                  var files = idFileFolder1.getFiles("*.indd");

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

                  {

                  app.open(File(files[myCounter]), true);

                  var myDoc=app.activeDocument;

                  with ( myDocument )

                  //file set in Bleed options.

          

      var myIndesignDoc=app.activeDocument;

      var myParStyles = myIndesignDoc.paragraphStyles;

      var myCharStyles = myIndesignDoc.characterStyles;

      var myUnusedSwatches = myIndesignDoc.unusedSwatches;

       

       

      for (var j=myIndesignDoc.unusedSwatches.length; j > 0; j--){

        myIndesignDoc.unusedSwatches[j-1].remove();   

      }

       

      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 = myIndesignDoc.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 = myIndesignDoc.findText();

            if (myFoundStyles == 0) {

               myChStyle.remove();

            }

         app.findTextPreferences = NothingEnum.nothing;

         app.changeTextPreferences = NothingEnum.nothing;

      }

                         {

                  app.activeDocument.save(File(files[myCounter]));

                  app.activeDocument.close();

                  //Note that you could also use:

                  }

                  }

                  }

                 }

      }

       

       

      catch ( err ) {

      // Silently fail

      }

      alert("All Indesign file remove para and character style");