2 Replies Latest reply on Nov 27, 2017 10:15 PM by johnt53984649

    Mass Crop and Conversion Script

    johnt53984649 Level 2

      This should be a fairly simple script, but I have decided to ask here because of my lack of experience.  The goal is to do a batch conversion of several thousand .eps files produced in an external application to .ai files, each of which are cropped in to remove all extra artboard space which is unused.  So essentially, I need it to do the following:

       

      1. Prompt the user to select multiple .eps files.
      2. Open the first .eps file.
      3. Remove the extra space by cropping (the same effect as going to Object -> Artwork -> Fit to Artwork Bounds)
      4. Save the current, modified document as an Illustrator file with the same name as the original file (but obviously the .ai extension instead of .eps).
      5. Close the current document without making changes to the original .eps file.
      6. Repeat steps 2 through 6 for the remainder of the files that were selected.

       

      Unfortunately, I have no idea how I could write a script to accomplish this.  Any examples would be greatly, greatly appreciated.  At the very least, help guide me in the right direction here.  Thank you so much.

        • 1. Re: Mass Crop and Conversion Script
          OMOTI Level 2

          Hi, johnt53984649.

           

          I made a simple example that added a process to make some artboards single.

          The following script don't set options for saving a document as an Illustrator file.

          If you need it, you can use IllustratorSaveOptions.

           

          Try this:

           

          #target Illustrator
          
          (function () {
              // 1. Prompt the user to select multiple .eps files.
              var files = File.openDialog("Select EPS files", undefined, true),
                  regExp = new RegExp(".eps$", "i"),
                  doc,
                  i,
                  max;
              if (files) {
                  // 6. Repeat steps 2 through 6 for the remainder of the files that were selected.
                  for (i = 0, max = files.length; i < max; i += 1) {
                      if (regExp.test(files[i].name)) {
                          // 2. Open the first .eps file.
                          doc = app.open(files[i]);
                          // (process to make some artboards single.)
                          while (doc.artboards.length !== 1) {
                              doc.artboards[0].remove();
                          }
                          // 3. Remove the extra space by cropping (the same effect as going to Object -> Artwork -> Fit to Artwork Bounds)
                          doc.artboards[0].artboardRect = doc.visibleBounds;
                          // 4. Save the current, modified document as an Illustrator file with the same name as the original file (but obviously the .ai extension instead of .eps).
                          doc.saveAs(new File(files[i].fsName.slice(0, -4) + ".ai"));
                          // 5. Close the current document without making changes to the original .eps file.
                          doc.close(SaveOptions.DONOTSAVECHANGES);
                      }
                  }
              }
          }());
          
          1 person found this helpful
          • 2. Re: Mass Crop and Conversion Script
            johnt53984649 Level 2

            This works beautifully and gave me a very good introduction to scripting for Illustrator.  Now I see how it all works.  Thank you so much!