unused paragraph character and swatches


hi all

 

i have create new script deleted unused paragraph, unused charaterstyle , unused swatches have not run in batch please check script , update me incorrect on script please me

 

 

//create manish bhatt (dmd)

try{

           // ask input , output folder (or hardcode define them if want)

           infoldername= folder.selectdialog ("input folder:");

           // infoldername = "/id files";

 

           if (infoldername != null )

           {

            var idfilefolder = new folder(infoldername);

            // if need script create folder, 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]);

            // list of files indesign files

            var files = idfilefolder1.getfiles("*.indd");

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

            {

            app.open(file(files[mycounter]), true);

            var mydoc=app.activedocument;

            ( 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; >= 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 use:

            }

            }

            }

           }

}

 

 

catch ( err ) {

// silently fail

}

alert("all indesign file remove para , character style");

use this,

 

         

try{

           // ask input , output folder (or hardcode define them if want)
            infoldername= folder.selectdialog ("input folder:");
           if (infoldername != null )
           {
            var idfilefolder = new folder(infoldername);
            var files;
            files = idfilefolder.getfiles("*.indd");

           for(mycounter = 0; mycounter < files.length; mycounter++)
          {
            app.scriptpreferences.userinteractionlevel = userinteractionlevels.never_interact;
            app.open(file(files[mycounter]), true);

                    var myindesigndoc=app.activedocument;
                    var myparstyles = myindesigndoc.paragraphstyles;
                    var mycharstyles = myindesigndoc.characterstyles;
                    var myunusedswatches = myindesigndoc.unusedswatches;
                    
                    (var j=myindesigndoc.unusedswatches.length; j > 0; j--){
                      myindesigndoc.unusedswatches[j-1].remove();  
                    }

                    (j = myparstyles.length-1; j >= 2; j-- ) {
                       removeunusedparastyle(myparstyles[j]);
                    }

                    (i = mycharstyles.length-1; >= 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();
            }
        }
}

catch ( err ) {

// silently fail

}

alert("all indesign file remove para , character style");



More discussions in InDesign Scripting


adobe

Comments

Popular posts from this blog

Upgrade 3.4.8 to 3.5.1 failed "download package failed" - Joomla! Forum - community, help and support

Fatal error during instalation - Joomla! Forum - community, help and support

Joomal 3.6.3 update error - PHP temporary folder is not set - Joomla! Forum - community, help and support