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:
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.
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.
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);
}
}
}
}());
Copy link to clipboard
Copied
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!