8 Replies Latest reply on Apr 12, 2016 8:55 AM by tpk1982

    Please improve my script

    tpk1982 Level 4

      Hi,

       

      I wrote script for finding text size lower than 6 pts, text leading lower than 3 pts, hyphenation and ligature On.

       

      It is working fine but taking too much time to process (let say 64 pages totally in my document), is it any modification done to improve its speed?

       

      mypoinsize();
      myleading();
      mylig();
      myhypandlig()
      
      function mypoinsize(){
      var myFrame=app.activeDocument.textFrames.length
      var flag2=0;
      for(i=0;i<myFrame;i++){
      for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){
      var myCV=app.activeDocument.textFrames.item(i).paragraphs.item(j).pointSize;
      var myCV1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().pointSize;
      if(myCV<6 || myCV1<6)
      {
      
      flag2=1
      }
      }
      }
      if(flag2==1)
      {
      alert("ERROR: Document contain less than 6 point size text"+"\r\r");
      
      
      }
      else
      {
      
      
      alert("Document doesn't contain less than 6 point size text"+"\r\r");
      }
      }              
      
      
      //leading
      function myleading(){
      
      
      var myFrame=app.activeDocument.textFrames.length
      var flag3=0;
      for(i=0;i<myFrame;i++){
      for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){
      var myCV=app.activeDocument.textFrames.item(i).paragraphs.item(j).leading;
      var myCV1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().leading;
      
      
      if(myCV<3 || myCV1<3)
      {
      
      
      flag3=1
      }
      }
      }
      
      
      if(flag3==1)
      {
      
      
      alert("ERROR: Document contain less than 3 point size leading"+"\r\r");
      
      
      }
      else
      {
      
      
      alert("Document doesn't contain less than 3 point size leading"+"\r\r");
      }
      }
      //hyp and lig
      function mylig(){
      var myFrame=app.activeDocument.textFrames.length
      var flag4=0;
      for(i=0;i<myFrame;i++){
      for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){
      var myResult=app.activeDocument.textFrames.item(i).paragraphs.item(j).hyphenation;
      var myResult1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().hyphenation;
      
      
      if(myResult==true || myResult1==true)
      {
      
      
      flag4=1
      }
      }
      }
      
      
      if(flag4==1)
      {
      
      
      alert("ERROR: Document contain Hyphenation"+"\r\r");
      
      
      }
      else
      {
      
      
      alert("Document doesn't contain Hyphenation"+"\r\r");
      }
      
      
      }       
      
      
      //hyp and lig
      function myhypandlig(){
      var myFrame=app.activeDocument.textFrames.length
      var flag4=0;
      for(i=0;i<myFrame;i++){
      for(j=0;j<app.activeDocument.textFrames.item(i).paragraphs.length;j++){
      myResult=app.activeDocument.textFrames.item(i).paragraphs.item(j).ligatures;
      var myResult1=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().ligatures;
      
      
      if(myResult==true || myResult1==true)
      {
      
      
      flag4=1
      }
      }
      }
      
      
      if(flag4==1)
      {
      
      
      alert("ERROR: Document contain Ligature "+"\r\r");
      
      
      }
      else
      {
      
      
      alert("Document doesn't contain Ligature"+"\r\r");
      }
      }    
      
      
      

       

      Advance thanks,

      Karthi

        • 1. Re: Please improve my script
          Vamitul Level 4

          why not use findGrep()?

          • 2. Re: Please improve my script
            tpk1982 Level 4

            Vamitul


            I tried the find option for ligature and hyphenation, but not sure how to find below 6 pt size texts and below 3 pt leading texts.

             

            app.findGrepPreferences = app.changeGrepPreferences = null;     
            var doc=app.activeDocument;
            var Frame = doc.allPageItems;
            for(var i=0;i<Frame.length;i++)
            {
              if(Frame[i] instanceof TextFrame)
                { 
                  app.findGrepPreferences = app.changeGrepPreferences =NothingEnum.nothing;
                  app.findGrepPreferences.findWhat = "\\S";
                  app.findGrepPreferences.ligatures = true;     
            
            
                  var found =  doc.findGrep();
                                if(found.length > 0)
                                {
                                    alert("ERROR: Document contain Ligature")
                                }
                            } 
                    }
            app.findGrepPreferences = app.changeGrepPreferences = null;     
            
            • 3. Re: Please improve my script
              Vamitul Level 4

              yes, you are right.

              • 4. Re: Please improve my script
                tpk1982 Level 4

                But how can i use findGrep() for finding point size and leading, any suggestions?

                • 5. Re: Please improve my script
                  Vamitul Level 4

                  Sorry, i'm tried and did not think things through. You cannot use findGrep() to search for text that is smaller than 6pt.

                  You could try something like:

                  doc.stories.everyItem().textStyleRanges.everyItem().pointSize

                  That would return a fairly large array with all the text sizes in your stories (tables, footnotes not included).

                  Then you can either iterate through it, or you can filter it, or just sort it and test for the first element.

                  • 6. Re: Please improve my script
                    tpk1982 Level 4

                    Hi Vamitul,

                     

                    Thank you for the idea. It works:

                     

                    mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements(); 
                    for (i=0; i<mytext.length; i++) 
                    { 
                    if (mytext[i].pointSize < 6) 
                    { 
                        alert("Some text have below 6 pt size");
                    } 
                    }
                    
                    • 7. Re: Please improve my script
                      Vamitul Level 4

                      You do realise that with that code, you will get an alert for each bit of text that is under 6 pt.

                      I'd rather do something like:

                       

                      var mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().pointSize;

                      mytext.sort();

                      while (mytext[0]===undefined){ //for some reason, we do get undefined values in some cases

                          mytext.shift();

                      }

                      if (mytext[0]<6){

                          alert('Bla bla blah. Text below 6pt');

                      }

                      • 8. Re: Please improve my script
                        tpk1982 Level 4

                        Yes, you are correct. I used flag to avoid the repeating instance like below upto my little knowledge

                         

                        mytext = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements(); 
                        var flag=0;
                        for (i=0; i<mytext.length; i++) 
                        { 
                        if (mytext[i].pointSize < 6) 
                        { 
                            flag=1
                        } 
                        }
                        if(flag==1) 
                        { 
                        alert("ERROR: Document contain less than 6 point size text"+"\r\r"); 
                        } 
                        else 
                        { 
                        alert("Document doesn't contain less than 6 point size text"+"\r\r"); 
                        } 
                        

                         

                         

                        but the mytext.sort(); is a learning for me, thanks