4 Replies Latest reply on Feb 27, 2016 1:31 PM by InfernoDandA

    Need a little help. Script to export single document to different file types.

    InfernoDandA Level 1

      Hey guys, I'm new to scripting. have searched all over but can not find an answer to this, I'm sure it's quite simple


      At work we are exporting logos all the time into a few different formats for clients.
      I've been looking into scripting as a way to automate the process.

       

      So far I've figured out a little script to export my Illustrator document into different formats... now I need to be able to export this same document out as a low & High res PNG, low and high res JPEGs, EPS, PDF & TIFF etc .
      I've got scripts to do all of these seperately but just need to know how to put it all together in a single script so I can do everything in one go

       

      Here is an example of my two different PNG export scripts. I just need to know how to string these together so I can add all the rest of the formats without breaking the whole thing.

       

      function savePNG(){ 
          var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
          if (destFolder) {
              if(app.documents.length > 0){ 
                  var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                  var destFile = new File(destFolder + '/' + docName + " - HR.png");
                  if(destFile == null){return;} 
                  var doc = app.activeDocument;   
                  var artRect = doc.artboards[0].artboardRect; 
                  var exportOptions = new ImageCaptureOptions; 
                  exportOptions.resolution = 300; 
                  exportOptions.antiAliasing = true; 
                  exportOptions.transparency = true; 
                  doc.imageCapture(destFile, artRect, exportOptions); 
              }
         
      savePNG(); 

       

      and here is the low res version

       

      function savePNG(){ 
          var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
          if (destFolder) {
              if(app.documents.length > 0){ 
                  var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                  var destFile = new File(destFolder + '/' + docName + " - LR.png");
                  if(destFile == null){return;} 
                  var doc = app.activeDocument;   
                  var artRect = doc.artboards[0].artboardRect; 
                  var exportOptions = new ImageCaptureOptions; 
                  exportOptions.resolution = 72; 
                  exportOptions.antiAliasing = true; 
                  exportOptions.transparency = true; 
                  doc.imageCapture(destFile, artRect, exportOptions); 
              }
         
      savePNG(); 

       

       

       

      Thanks for any advice you can give!
      Eli

        • 1. Re: Need a little help. Script to export single document to different file types.
          CarlosCanto Adobe Community Professional & MVP

          there are several ways, one of the easiest would be to bring up a prompt to let the user enter for example 1 for HR, or 2 for LR, then based on the input, do either 72 or 300 and adjust the names.

           

          function main () {
              var title = 'Image Capture Script';
              var a = prompt ('Enter 1 for HR, or 2 for LH', 1, title);
              if (a==null) return;
              else {
                  if (a==1) {
                      res = 300;
                      suffix = ' - HR.png';
                  }
                  else if (a==2) {
                      res = 72;
                      suffix = ' - LH.png';
                  }
                  else {
                      alert('Enter either 1 or 2 only');
                      return;
                  }
              }
              savePNG (res, suffix);
          }
          
          
          main();
          
          
          function savePNG(resolution, suffix){
              var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
              if (destFolder) {
                  if(app.documents.length > 0){
                      var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                      var destFile = new File(destFolder + '/' + docName + suffix);
                      if(destFile == null){return;}
                      var doc = app.activeDocument; 
                      var artRect = doc.artboards[0].artboardRect;
                      var exportOptions = new ImageCaptureOptions;
                      exportOptions.resolution = resolution;
                      exportOptions.antiAliasing = true;
                      exportOptions.transparency = true;
                      doc.imageCapture(destFile, artRect, exportOptions);
                  }
              }
          }
          
          • 2. Re: Need a little help. Script to export single document to different file types.
            InfernoDandA Level 1

            Thanks for the reply Carlos.

             

            This isn't really what I'm looking for as I could just run the seperate scripts to get the same result.

             

            I just want a way to combine them so the will all run in one go (saving me time of manually choosing different options or running 6 different scripts per document to export what I need)

            I know it's probably very simple thing to do I just don't know how to string them all together while exporting out all the different settings (such as the low res & high res PNG's)

            • 3. Re: Need a little help. Script to export single document to different file types.
              CarlosCanto Adobe Community Professional & MVP

              oh, you want to run both functions one after the other at the same time? then just name them with different names and run one function after the other, if all files will be saved in the same folder, move the selectDialog method out of each of your functions to get it only once.

               

              function savePNG_HR(){
                  var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
                  if (destFolder) {
                      if(app.documents.length > 0){
                          var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                          var destFile = new File(destFolder + '/' + docName + " - HR.png");
                          if(destFile == null){return;}
                          var doc = app.activeDocument; 
                          var artRect = doc.artboards[0].artboardRect;
                          var exportOptions = new ImageCaptureOptions;
                          exportOptions.resolution = 300;
                          exportOptions.antiAliasing = true;
                          exportOptions.transparency = true;
                          doc.imageCapture(destFile, artRect, exportOptions);
                      }
                  }
              }
              
              
              function savePNG_LR(){
                  var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
                  if (destFolder) {
                      if(app.documents.length > 0){
                          var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                          var destFile = new File(destFolder + '/' + docName + " - LR.png");
                          if(destFile == null){return;}
                          var doc = app.activeDocument; 
                          var artRect = doc.artboards[0].artboardRect;
                          var exportOptions = new ImageCaptureOptions;
                          exportOptions.resolution = 72;
                          exportOptions.antiAliasing = true;
                          exportOptions.transparency = true;
                          doc.imageCapture(destFile, artRect, exportOptions);
                      }
                  }
              }
              savePNG_HR();
              savePNG_LR();
              
              • 4. Re: Need a little help. Script to export single document to different file types.
                InfernoDandA Level 1

                Perfect, this is exactly what I need.

                 

                Thanks for the help Carlos.