4 Replies Latest reply on Mar 18, 2017 3:12 AM by Colin Flashman

    Issues with preflight script

    Colin Flashman Adobe Community Professional

      I'm working on a script that would make it impossible to export a PDF unless there are no preflight errors.

       

      I've done this by creating a startup script that has an eventlistener that will run the script after the export option has been chosen, but before the export save dialog begins. The script works in two ways: if preflight is off, an alert pops up saying "turn it on". If preflight is on, it determines if there are 0 errors, and if so, proceeds to export... if not, displays an error.

       

      The code is here:

       

      #targetengine "session"
      main();    
      function main(){    
      
      var  beforeExport = app.menuActions.itemByName ( "$ID/Export..." ).addEventListener ( "beforeInvoke", checkJob );  
           
      function checkJob(myEvent){    
      if(app.activeDocument.preflightOptions.preflightOff == true){
      alert('Hey, turn your preflight on!');
        exit(0);
      }else{
              var my_profile = app.preflightProfiles.firstItem();
              var my_process = app.preflightProcesses.add(app.activeDocument, my_profile);
              my_process.waitForProcess();
              results = my_process.processResults;
      
      var myTest = results.indexOf("None");
      if (myTest == 0)
      {
      //alert ("No errors found");
      }
      else
      {
      alert ("Errors found");
      }
      };   
      }  
      }   
      

       

      However, there are two improvements I'm struggling to make and I'm looking for suggestions:

       

      1) After an alert (meaning preflight wasn't on or it wasn't free of errors) I'd like the export dialog to stop completely, but at the moment the error dialogs will appear but the export continues on regardless. Is there a way to do this?

      2) The variable "my_profile" I'm having trouble assigning it to the profile that is selected by the end-user. I've tried selectedIndex and been through the list here InDesign ExtendScript API (12.0)  but can't seem to get the end-user selected profile. The one I settled on for the above script was the first item that shows up in the end-user list.

       

      Can anyone suggest any solutions or workarounds that may assist me with this script?

       

      Many thanks

       

      Colin

        • 1. Re: Issues with preflight script
          Loic.Aigon Adobe Community Professional
          #targetengine "onExport"  
          main();      
          function main(){      
            
          var  beforeExport = app.menuActions.itemByName ( "$ID/Export..." ).addEventListener ( "beforeInvoke", checkJob );    
                 
          function checkJob(myEvent){      
          if(app.activeDocument.preflightOptions.preflightOff == true){  
          alert('Hey, turn your preflight on!');  
          myEvent.preventDefault();
          myEvent.stopPropagation();
            exit(0);  
          }else{  
                  var my_profile = app.preflightProfiles.firstItem();  
                  var my_process = app.preflightProcesses.add(app.activeDocument, my_profile);  
                  my_process.waitForProcess();  
                  results = my_process.processResults;  
            
          var myTest = results.indexOf("None");  
          if (myTest == 0)  
          {  
          //alert ("No errors found");  
          }  
          else  
          {  
          alert ("Errors found");  
          }  
          };     
          }    
          } 
          

           

          Use

           

          myEvent.preventDefault();

          myEvent.stopPropagation();

           

          HTH

          Loic

          • 2. Re: Issues with preflight script
            Colin Flashman Adobe Community Professional

            Thank you Loic, that did the trick for that issue.

             

            I still have an issue concerning that was the second part of my two-part question, and that was:

            • the variable "my_profile" I'm having trouble assigning it to the profile that is selected by the end-user. I've tried selectedIndex and been through the list here InDesign ExtendScript API (12.0)  but can't seem to get the end-user selected profile.

            The one I settled on for the original script was the first item that shows up in the end-user list, but if the user changes profile while they're working on the job, the profile that the original script referred to was the profile that was at the top of the list when the document was opened.

             

            Nevertheless, this first solution is very helpful and I can continue improving the script in other ways.

             

            Thank you very much.

             

            Colin

            • 3. Re: Issues with preflight script
              Colin Flashman Adobe Community Professional

              I've worked out the second part of the problem. I didn't need to add a preflight process, just use the one that was selected i.e.

               

              var my_process = app.preflightProcesses[0];
              

               

              Here is the full code, should anyone want to make the lives of their designers more frustrating by making them conform to using the preflight profiles! Sure, they can cheat and use the [Basic] profile, but the script can be adjusted to ensure that staff are using a specifically named preset.

               

              #targetengine "session"
              main();    
              function main(){    
              var  beforeExport = app.menuActions.itemByName ( "$ID/Export..." ).addEventListener ( "beforeInvoke", checkJob );  
              function checkJob(myEvent){    
              if(app.activeDocument.preflightOptions.preflightOff == true){
              alert('You have not preflighted your artwork.\rPlease preflight your artwork using the preflight panel before trying again.');
              app.panels.itemByName("$ID/kPreflightUIPaletteName").visible = true;
              app.activeDocument.preflightOptions.preflightOff = false;
              myEvent.preventDefault();  
              myEvent.stopPropagation();  
              exit(0);
              }else{
                      var my_process = app.preflightProcesses[0];
                      results = my_process.processResults;
              
              var myTest = results.indexOf("None");
              if (myTest == 0)
              {
              }
              else
              {
              alert ('This artwork contains preflight errors.\rPlease resolve these errors using the preflight panel and try again.');
              app.panels.itemByName("$ID/kPreflightUIPaletteName").visible = true;
              myEvent.preventDefault();  
              myEvent.stopPropagation();  
              exit(0);
              }
              };   
              }  
              }   
              
              

               

              Hey, why stop there... why not include printing as well? Add this line after line 4:

               

              var  beforePrint = app.menuActions.itemByName ( "$ID/kPrint" ).addEventListener ( "beforeInvoke", checkJob );      
              
              • 4. Re: Issues with preflight script
                Colin Flashman Adobe Community Professional

                Nope, nope, nope... as usual I have it completely wrong.

                 

                To include the beforePrint would be the following code:

                 

                var  beforePrint = app.menuActions.itemByName ( "$ID/Print..." ).addEventListener ( "beforeInvoke", checkJob );        
                 
                
                
                
                

                 

                The code that I had to choose whatever preflight was selected fails the moment the preflight On checkbox is clicked, so the following code is INCORRECT:

                 

                        var my_process = app.preflightProcesses[0];  
                
                
                

                 

                So that leaves me in the same circumstances I was in before, that is I need the script to determine whatever preflight was selected previously - use that... but I can't call it by it's name because I've no idea what the name of the preflight could be. So using a solution like this:

                 

                var process = app.preflightProcesses.add(myDocument, profile);
                process.waitForProcess();
                results = process.processResults;
                

                 

                won't work because the profile variable isn't a fixed name, but whatever the client has selected when preflighting their document.

                 

                Sorry to keep yapping on about this but I was so close!