Highlighted

Save As Script - Path definition and naming

Community Beginner ,
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.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

101

Likes

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

Save As Script - Path definition and naming

Community Beginner ,
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.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

102

Likes

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
Aug 11, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Aug 11, 2020 1
Community Beginner ,
Aug 11, 2020

Copy link to clipboard

Copied

oh, didn't know that. Thank you very much 🙂

Likes

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
Reply
Loading...
Aug 11, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Aug 11, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Aug 11, 2020 0
Community Beginner ,
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?

Likes

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
Reply
Loading...
Aug 12, 2020 0
Engaged ,
Aug 12, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 12, 2020 1
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Aug 12, 2020 0
Engaged ,
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.

Likes

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
Reply
Loading...
Aug 12, 2020 0
Community Beginner ,
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

Likes

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
Reply
Loading...
Aug 12, 2020 0
Engaged ,
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

Likes

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
Reply
Loading...
Aug 12, 2020 1
Community Beginner ,
Aug 12, 2020

Copy link to clipboard

Copied

Ok thank you... it worked!

Likes

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
Reply
Loading...
Aug 12, 2020 0