• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Mass Crop and Conversion Script

Engaged ,
Nov 26, 2017 Nov 26, 2017

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

621

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Nov 27, 2017 Nov 27, 2017

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.

...

Votes

Translate

Translate
Adobe
Contributor ,
Nov 27, 2017 Nov 27, 2017

Copy link to clipboard

Copied

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.name)) {

                // 2. Open the first .eps file.

                doc = app.open(files);

                // (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.fsName.slice(0, -4) + ".ai"));

                // 5. Close the current document without making changes to the original .eps file.

                doc.close(SaveOptions.DONOTSAVECHANGES);

            }

        }

    }

}());

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 27, 2017 Nov 27, 2017

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines