9 Replies Latest reply on May 14, 2011 11:36 AM by tpk1982

    Help Please

    tpk1982 Level 4

      Hi,

       

      In my document i have two master pages namely "A-Master" and "AS-A Short". I used the "AS-A Short" whenever need one line short in document. I have not to apply "AS-A Short" master more than 3 spread continuously. Is there any script to find this kind of issues and alert it. And is it posssible the result can store as .txt file?

       

      Thanks in advance

       

      master.jpg

        • 1. Re: Help Please
          Haakenlid Level 3

          Does this do what you want?

           

           

          var myMaster = "AS-A Short";
          var myDoc = app.activeDocument;
          var counter = 0;
          var maxValue = 3;
          var report = "";
          
          for (var n=0; n<myDoc.spreads.length; n++){
              if (myDoc.spreads[n].appliedMaster.name == myMaster){
                  counter++;
              } else {
                  counter = 0;
              }
              if (counter > maxValue){
                  report += "\nSpread "+myDoc.spreads[n].pages[0].name+"-"+myDoc.spreads[n].pages[-1].name+" has "+ myMaster + " applied as spread number "+ counter + " in a row."
              }
          }
          
          if (report == ""){
              report = "No warnings";
          }
          
          alert (report, "Spreads with "+myMaster)
          

           

           

          It's also simple to output the report as a txt. Just add this at the end of the script.

           

           

          var filePath = "~/Desktop/report.txt"; // or wherever you want to put your file
          var myFile = new File(filePath)
          myFile.open("w");
          myFile.write(report);
          myFile.close();
          
          • 2. Re: Help Please
            tpk1982 Level 4

            Hi,

             

            Awesome!! So quick you are. Thank you so much.

             

            I have another question, forget to ask first. Sometimes my document have more than 2 master pages like "A-Master" and short for this one("AS-A Short), "B-Master" and "BS-B Short" and so on. In this case how can we detect? This script only look A short. At last my requirement is if any short pages applied more than 3 then we have to report. Is it possible? Sorry to bother you.

             

            I have another two scripts for various purposes, i want that results also to be in same this .txt file? can we do?

             

            Thanks

            • 3. Re: Help Please
              aanavaras

              Hi,

               

              It's so simple.

               

              try this (the same code with some changes):

              var myDoc = app.activeDocument;
              var myMaster;
              var counter = 0;
              var maxValue = 3;
              var report = "";

              for (var n=0; n<myDoc.spreads.length; n++)

              {    myMaster=myDoc.spreads[n].appliedMaster.name;
                   if (myMaster.search(/ Short/i) > 0)
                   {
                       counter++;
                   } else {
                       counter = 0;
                   }
                   if (counter > maxValue)
                   {
                       report += "\nSpread "+myDoc.spreads[n].pages[0].name+"-"+myDoc.spreads[n].pages[-1].name+" has "+ myMaster + " applied as spread number "+ counter + " in a row."
                   }
              }

              if (report == "")

              {
                   report = "No warnings";
              }

              alert (report, "Spreads with " + myMaster);

              this will check for 3 continues 'short' masters and reports.

               

              and, you have to write the txt file in append mode to view the all logs in a single file.

               

              function WriteToFile(sText)
              {
                  var fso = new ActiveXObject("Scripting.FileSystemObject");
                  var s = fso.CreateTextFile("C:\\test.txt", append, true);     // Your file name here.
                  s.WriteLine(report);     // the string to be written in the file.
                  s.Close();
              }

               

              Hope this helps you.

              1 person found this helpful
              • 4. Re: Help Please
                Haakenlid Level 3

                This will detect any master spread with the word "short" in them

                 

                var myMaster;
                var mySpread;
                var myDoc = app.activeDocument;
                var counter = 0;
                var maxValue = 3;
                var report = "";
                
                for (var n=0; n<myDoc.spreads.length; n++){
                    mySpread = myDoc.spreads[n];
                    if (mySpread.appliedMaster.name.match(/short/i)){
                        if (mySpread.appliedMaster != myMaster){
                            counter = 1;
                        } else {
                            counter ++;
                        }
                    } else {
                        counter = 0;
                    }
                    if (counter > maxValue){
                        report += "\nSpread "+mySpread.pages[0].name+"-"+mySpread.pages[-1].name+" has "+ mySpread.appliedMaster.name + " applied as spread number "+ counter + " in a row."
                    }
                    myMaster = mySpread.appliedMaster;
                }
                
                if (report == ""){
                    report = "No warnings";
                }
                
                alert (report, "Spreads with Short masterpage")
                
                var filePath = "~/Desktop/report.txt";
                var myFile = new File(filePath)
                myFile.open("w");
                myFile.write(report);
                myFile.close();
                
                

                 

                I have another two scripts for various purposes, i want that results also to be in same this .txt file? can we do?

                 

                You can add whatever you want to the report. Just add it to the string variable called "report"

                You can also append the txt file whenever you run the script, instead of overwriting it. Like this:

                report = "------------------------------------- "+myDoc.name+" -------------------------------------\n"+new Date().toLocaleString() +"\n"+ report + "\n\n"
                
                var filePath = "~/Desktop/report.txt";
                var myFile = new File(filePath)
                myFile.open("e");
                myFile.seek(0,2);
                myFile.write(report);
                myFile.close();
                
                
                1 person found this helpful
                • 5. Re: Help Please
                  tpk1982 Level 4

                  SUPER!! THANKS A LOT BOTH OF YOU.

                   

                   

                  But In Saravanan script, i don't get txt file. I am not sure, i am using MAC now. Hope this will work in PC.

                   

                  In Haakenlid, it does not catch the error if i used two different master pages. Like i use B short on verso and A short in Recto, then 3 short pages.

                   

                  Anyhow this is so helpful, thanks guys

                  • 6. Re: Help Please
                    Haakenlid Level 3

                    tpk1982 wrote:

                     

                    SUPER!! THANKS A LOT BOTH OF YOU.

                     

                     

                    But In Saravanan script, i don't get txt file. I am not sure, i am using MAC now. Hope this will work in PC.

                     

                     

                    Aanavaras is using some ActiveX stuff to make the txt-file. I can't get it to work, either. Extendscript has a native File object that will work both on macOS and windows.

                     

                     

                     

                    In Haakenlid, it does not catch the error if i used two different master pages. Like i use B short on verso and A short in Recto, then 3 short pages.

                     

                     

                    No. It only looks for 3 or more whole spreads with the exact same masterspread applied.

                     

                    If you want to look for mixes of the short styles as well you can use this loop:

                     

                    for (var n=0; n<myDoc.spreads.length; n++){
                        mySpread = myDoc.spreads[n];
                        if (mySpread.pages[0].appliedMaster.name.match(/short/i)||mySpread.pages[-1].appliedMaster.name.match(/short/i)){
                            counter ++;
                        } else {
                            counter = 0;
                        }
                        if (counter > maxValue){
                            report += "\nSpread "+mySpread.pages[0].name+"-"+mySpread.pages[-1].name+" has Short applied as spread number "+ counter + " in a row."
                        }
                        myMaster = mySpread.appliedMaster;
                    }
                    
                    • 7. Re: Help Please
                      tpk1982 Level 4

                      Hi,

                       

                      Thanks for spending time for me. Yes, its working now perfetly.

                       

                       

                      Last one thing, my previous question, you gave the solution, that the .txt file updates automatically instead of overwriting. Actually my question is, i run two more script, i want that result also in same .txt file. Is it i copy the two script and make it one, it process on by one, and report in single txt file. Is it possible?

                       

                       

                      I hope i bother you a lot. But i need your help.

                       

                      Thanks in advance.

                      • 8. Re: Help Please
                        Haakenlid Level 3

                        tpk1982 wrote:

                         

                        Hi,

                         

                        Thanks for spending time for me. Yes, its working now perfetly.

                         

                         

                        Last one thing, my previous question, you gave the solution, that the .txt file updates automatically instead of overwriting. Actually my question is, i run two more script, i want that result also in same .txt file. Is it i copy the two script and make it one, it process on by one, and report in single txt file. Is it possible?

                         

                         

                        I hope i bother you a lot. But i need your help.

                         

                        Thanks in advance.

                         

                        Yes this is possible. Just add this function to the end of your scripts, but change the dummytext to a string that contains whatever you want to add to the report.

                         

                        writeToFile("put whatever string you want here","~/Desktop/report.txt");
                        
                        function writeToFile(myReport, filePath){
                            var myFile = new File(filePath);
                            myReport = "-------------------------------------------------------------------\n"+new Date().toLocaleString() +"\n"+ myReport + "\n\n";
                            myFile.open("e");
                            myFile.seek(0,2);
                            myFile.write(myReport);
                            myFile.close();
                        };
                        

                        • 9. Re: Help Please
                          tpk1982 Level 4

                          Thats it, excellent work. my immense thanks to you. I sent a private mail to you. Awaiting for your reply.