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

Save As Script - Path definition and naming

Community Beginner ,
Aug 11, 2020 Aug 11, 2020

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

 

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

Screenshot 2020-08-11 at 2.51.27 PM.pngexpand image

 

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
1.4K
Translate
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
...
Translate
Adobe
Community Expert ,
Aug 11, 2020 Aug 11, 2020

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.

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

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?

Translate
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

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

Translate
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

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

Translate
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

Woops...

ok I did add it and i got this

Screenshot 2020-08-12 at 10.50.35 AM.pngexpand image

Translate
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

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

Translate
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
LATEST

Ok thank you... it worked!

Translate
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

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.

Translate
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