Export Script For Illustrator To Save For Web Jpg
Solution 1:
Here is the script as per your requirement. I have just updated Script 1 to match your requirement. By default it assumes ruler is in Points and convert it into inches and use in the file name. You can add more check to handle other ruler units. This will have a-z if artboards are not more than 26 in case artboards are more than 26, it will show something else. Using ASCII code for this
varfolder= Folder.selectDialog();
if (folder) {
varfiles= folder.getFiles("*.ai");
for (vari=0; i < files.length; i++) {
varcurrentFile= files[i];
app.open(currentFile);
varactiveDocument= app.activeDocument;
varjpegFolder= Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
varcodeStart=97; // for a;for (varj=0; j < activeDocument.artboards.length; j++) {
varactiveArtboard= activeDocument.artboards[j];
activeDocument.artboards.setActiveArtboardIndex(j);
varbounds= activeArtboard.artboardRect;
varleft= bounds[0];
vartop= bounds[1];
varright= bounds[2];
varbottom= bounds[3];
varwidth= right - left;
varheight= top - bottom;
if (app.activeDocument.rulerUnits == RulerUnits.Points) { //Add more if for more conversions
width = width / 72;
height = height / 72;
}
varfileName= activeDocument.name.split('.')[0] + "-" + String.fromCharCode(codeStart) + "-" + width + "x" + height + ".jpg";
vardestinationFile= File(jpegFolder + "/" + fileName);
vartype= ExportType.JPEG;
varoptions=newExportOptionsJPEG();
options.antiAliasing = true;
options.artBoardClipping = true;
options.optimization = true;
options.qualitySetting = 100; // Set Quality Setting
activeDocument.exportFile(destinationFile, type, options);
codeStart++;
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
currentFile = null;
}
}
Solution 2:
Here is the javascript code that will export all ai files present in the selected folder into a jpg. This code will ask you to select a folder. So select folder that will have 700 files
Script 1: Using JPEGQuality
varfolder= Folder.selectDialog();
if (folder) {
varfiles= folder.getFiles("*.ai");
for (vari=0; i < files.length; i++) {
varcurrentFile= files[i];
app.open(currentFile);
varactiveDocument= app.activeDocument;
varjpegFolder= Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
for (varj=0; j < activeDocument.artboards.length; j++) {
varactiveArtboard= activeDocument.artboards[0];
activeDocument.artboards.setActiveArtboardIndex(j);
varfileName= activeDocument.name.split('.')[0] + "Artboard" + (j + 1) + ".jpg";
vardestinationFile= File(jpegFolder + "/" + fileName);
vartype= ExportType.JPEG;
varoptions=newExportOptionsJPEG();
options.antiAliasing = true;
options.artBoardClipping = true;
options.optimization = true;
options.qualitySetting = 100; // Set Quality Setting
activeDocument.exportFile(destinationFile, type, options);
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
currentFile = null;
}
}
Since you have two artboards in each ai file. It will create two separate jpg for each artboard. You can change file name and folder location for jpg images as per requirement.
Script 2: By changing resolution
varfolder= Folder.selectDialog();
if (folder) {
varfiles= folder.getFiles("*.ai");
for (vari=0; i < files.length; i++) {
varcurrentFile= files[i];
app.open(currentFile);
varactiveDocument= app.activeDocument;
varjpegFolder= Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
varfileName= activeDocument.name.split('.')[0] + ".jpg";
vardestinationFile= File(jpegFolder + "/" + fileName);
// Export Artboard where you can set resolution for an image. Set to 600 by default in code.varopts=newImageCaptureOptions();
opts.resolution = 600;
opts.antiAliasing = true;
opts.transparency = true;
try {
activeDocument.imageCapture(newFile(destinationFile), activeDocument.geometricBounds, opts);
} catch (e) {
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
currentFile = null;
}
}
For script 2, there will be only single file for one ai file, irrespective of the artboards. SO you can run both script for your work and go ahead.
Solution 3:
VBA example that uses one Excel-specific statement
Sub Export_All()
Dim fs AsObjectDim aiRef AsObjectDim docRef AsObjectDim jpegExportOptions AsObjectDim f AsObjectDim p AsStringSet fs = CreateObject("Scripting.FileSystemObject")
Set aiRef = CreateObject("Illustrator.Application")
Set jpegExportOptions = CreateObject("Illustrator.ExportOptionsJPEG")
' Specify all export options here
jpegExportOptions.AntiAliasing = False
jpegExportOptions.QualitySetting = 70
p = Application.ActiveWorkbook.Path ' Excel-specific. You may change it to whatever you likeForEach f In fs.GetFolder(p).Files
If LCase(Right(f.Name, 3) = ".ai") Then
Debug.Print f.Name
Set docRef = aiRef.Open(p + "\" + f.Name)
Call docRef.Export(p + "\" + f.Name + ".jpg", 1, jpegExportOptions)
Set docRef = NothingEndIfNext' Note that AI is still open and invisibleEndSub
Post a Comment for "Export Script For Illustrator To Save For Web Jpg"