Skip to main content
Inspiring
January 21, 2019
Answered

Create folder + save artboard in it

  • January 21, 2019
  • 1 reply
  • 1677 views

Hi,

I created a script to check if the folder is created and if not it will create it.
Then I save my 2 artboards (its a master file so users will always have the two artboards) into this folder.
The folder is named after the artboard 1 (which is index 0).

I then save my file before starting to export (because I guess once I'll export the eps my file will be the eps it self)Once saved I save my first artboard in jpeg in this folder.

Once done I save my second artboard (index 1) to the same folder in jpeg + eps.

Questions are :

- Why won't it run?.. nothing happens when I run the script in illustrator.

- Will the eps file have only the arts within the artboard? if not, is there a way to delete what's out of bound and only keep what's within this said artboard?

maybe changing "saveDoc= app.activeDocument;" by the artboard(1)?

Thanks a lot guys. This forum been really helpful.

It's only my fourth script so it might be messy a bit.

var targetDoc = app.activeDocument;

var Name = targetDoc.artboards[0].name;

var folder = new Folder ("F:/DevEcusson/" + Name);

function main ()

{

if (!folder.exists)   folder.create();

targetDoc.save();

SaveArtboard1();

saveArtboard2();

}

function SaveArtboard1 ()

{

app.activeDocument.artboards.setActiveArtboardIndex(0);

var jpgName = targetDoc.artboards[0].name + ".jpeg";

exportFileToJPEG (folder + jpgName, 72);

}

function SaveArtboard2 ()

{

app.activeDocument.artboards.setActiveArtboardIndex(1);

var jpgName = targetDoc.artboards[1].name + ".jpeg";

var epsName = targetDoc.artboards[1].name + ".eps";

exportFileToJPEG (folder + jpgName, 72);

exportFileAsEps (folder + epsName);

}

function exportFileToJPEG (dest, resolution)

{

var exportOptions = new ExportOptionsJPEG();

var type = ExportType.JPEG;

var fileSpec = new File(dest);

exportOptions.antiAliasing = true;

exportOptions.artBoardClipping = true;

exportOptions.horizontalScale = resolution*100/72;

exportOptions.verticalScale = resolution*100/72;

exportOptions.qualitySetting = 100;

app.activeDocument.exportFile( fileSpec, type, exportOptions );

}

function exportFileAsEps (destFile)

{

var newFile = new File(destFile);

var saveDoc;

if (app.documents.lenght == 0)

saveDoc = app.documents.add();

else

saveDoc= app.activeDocument;

saveOpts.cmykPostScript = true;

saveOpts.emdedAllFonts = true;

saveDoc.saveAs(newFile, saveOpts);

}

This topic has been closed for replies.
Correct answer pixxxelschubser

Didn't seen your edited answer.

for saving one artboard try these properties:

saveOpts.saveMultipleArtboards = false;   

saveOpts.artboardRange = "1"; // artboard # 1 

Aktualisiert

set saveMultipleArtboards to true for saving a range or a single artboard

1 reply

pixxxelschubser
Community Expert
Community Expert
January 21, 2019

You didn't call the function main with:

main();

(but there are also other mistakes)

Inspiring
January 21, 2019

oh...

there are days I'm wondering if i'm still in bed... today is one of them.

That's a good start. I will try to find the other fixes to do...

Thanks for pointing out! Really appreciated.

Tested the code adding the "main();" to call it, made few changes here and there to fix mistakes... and It now works the way I want it to work... but I still have to work on the eps part...
Not sure to get how to call the artboard range to save only artboard(1)...

pixxxelschubser
Community Expert
Community Expert
January 21, 2019

I will work on that and try to come up with something to make the eps export work tomorrow when I come back at the office.

thanks for helping!


Do you use the ESTK?

Have a look on this: