Copy link to clipboard
Copied
Hello all!
I'm new to scripting and my coding knowledge is quite limited. I'm trying to:
1. Locate Parent folder (02 FINALS), then EPS folder and save there a new .ai file with the same name as the original + "outlined" at the end.
2. The new file must be cs6 with these first 4 options checked:
 
Here is my so far code:
function exportFileToAI() {
if (app.documents.length > 0) {
var ai6Doc = app.activeDocument.path;
var saveOptions = new IllustratorSaveOptions();
saveOptions.compatibility = Compatibility.ILLUSTRATOR6;
saveOptions.pdfCompatible = true;
saveOptions.embedLinkedFiles = true;
saveOptions.embedICCProfile = true;
saveOptions.compressed = true;
app.activeDocument.saveAs(ai6Doc, saveOptions);
}
}
...and I am stuck.
Any help will be greatly appreciated.
Thank you.
1 Correct answer
Try the following
function exportFileToAI() {
if (app.documents.length > 0) {
var ai6Doc = app.activeDocument.path;
var parentPath = ai6Doc.parent
var epsFolder = parentPath + "/EPS/"
var newFPath = new File(epsFolder + app.activeDocument.name.split(".")[0] + "outlined.ai")
var saveOptions = new IllustratorSaveOptions();
saveOptions.compatibility = Compatibility.ILLUSTRATOR16;
saveOptions.pdfCompatible = true;
saveOptions.embedLinkedFiles = true;
saveOptions.embedICCProfile
...
Explore related tutorials & articles
Copy link to clipboard
Copied
I can't help you with the rest, but I should just point out that this:
saveOptions.compatibility = Compatibility.ILLUSTRATOR6;
gives compatibility with Illustrator version 6 (1996). Illustrator CS6 is version 16.
Copy link to clipboard
Copied
oh, didn't know that. Thank you very much 🙂
Copy link to clipboard
Copied
Hi Doug, shouldn't it be Compatibility.ILLUSTRATOR16 instead of Compatibility.ILLUSTRATOR6
As you mentioned CS6 is version 16 and even the API documentation describes the values from Compatibility.ILLUSTRATOR8 onwards.
-Manan
Copy link to clipboard
Copied
Try the following
function exportFileToAI() {
if (app.documents.length > 0) {
var ai6Doc = app.activeDocument.path;
var parentPath = ai6Doc.parent
var epsFolder = parentPath + "/EPS/"
var newFPath = new File(epsFolder + app.activeDocument.name.split(".")[0] + "outlined.ai")
var saveOptions = new IllustratorSaveOptions();
saveOptions.compatibility = Compatibility.ILLUSTRATOR16;
saveOptions.pdfCompatible = true;
saveOptions.embedLinkedFiles = true;
saveOptions.embedICCProfile = true;
saveOptions.compressed = true;
app.activeDocument.saveAs(newFPath, saveOptions);
}
}
-Manan
Copy link to clipboard
Copied
Hey, thank you very much. It seems that i stumbled upon another problem. Every time i run the script nothing happens. I have no feedback from the system meaning something like "alert error in line 25 etc...". Nothing happens, no new file, no nothing. First time i run it i assumed it worked bcz of the lack of feedback. And i assume the code is correct but still... any tips?
Copy link to clipboard
Copied
Are you running it on an untitled file that you haven't saved anywhere yet?
Copy link to clipboard
Copied
I hope you did add the method call statement to the code i have, i.e. the following
exportFileToAi()
If not then add it as the last line of the script. If it still does not work, then can you send a video of the whole process on your end.
-Manan
Copy link to clipboard
Copied
Woops...
ok I did add it and i got this
Copy link to clipboard
Copied
Your "Ai" in the function name at the bottom is not capitalized, ha. It should be "AI". Happens to all of us, but that's an advantage to using an editor like VSCode instead of plaintext
Copy link to clipboard
Copied
Ok thank you... it worked!
Copy link to clipboard
Copied
Try this:
function exportFileToAI() {
if (app.documents.length > 0) {
var path =
app.activeDocument.path.length > 0
? app.activeDocument.path.parent
: Folder.desktop;
var folder = Folder((path += "/EPS/"));
if (!folder.exists) folder.create();
path +=
app.activeDocument.name.replace(/\.[^(\\|\/)]*$/, "") + "outlined.ai";
var newFPath = File(path);
var saveOptions = new IllustratorSaveOptions();
saveOptions.compatibility = Compatibility.ILLUSTRATOR16;
saveOptions.pdfCompatible = true;
saveOptions.embedLinkedFiles = true;
saveOptions.embedICCProfile = true;
saveOptions.compressed = true;
app.activeDocument.saveAs(newFPath, saveOptions);
}
}
I think this should work even if you haven't saved the file before or a path resolution error happens when the folder doesn't exist.

