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

Save As Script - Path definition and naming

Community Beginner ,
Aug 11, 2020 Aug 11, 2020

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.

Screenshot 2020-08-11 at 2.29.22 PM.png

 

2. The new file must be cs6 with these first 4 options checked:

Screenshot 2020-08-11 at 2.51.27 PM.png

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.

TOPICS
Scripting

Views

907

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

Community Expert , Aug 11, 2020 Aug 11, 2020

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 11, 2020 Aug 11, 2020

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.

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
Community Beginner ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

oh, didn't know that. Thank you very 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
Community Expert ,
Aug 11, 2020 Aug 11, 2020

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

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
Community Expert ,
Aug 11, 2020 Aug 11, 2020

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

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
Community Beginner ,
Aug 12, 2020 Aug 12, 2020

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?

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
Enthusiast ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

Are you running it on an untitled file that you haven't saved anywhere yet?

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
Community Expert ,
Aug 12, 2020 Aug 12, 2020

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

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
Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

Woops...

ok I did add it and i got this

Screenshot 2020-08-12 at 10.50.35 AM.png

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
Enthusiast ,
Aug 12, 2020 Aug 12, 2020

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

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
Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

LATEST

Ok thank you... it worked!

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
Enthusiast ,
Aug 12, 2020 Aug 12, 2020

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.

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