为 illustrator 导出脚本以保存为 web jpg
Export script for illustrator to save for web jpg
任何人都可以帮我为 illustrator CC2017 编写一个脚本,将文件导出到 Web(旧版)为 JPG,然后保存文件并在之后关闭。我有 700 个文件,每个文件有 2 个艺术板,单击文件>导出>保存为 Web(旧版)然后正确的文件名并保存文件然后关闭会很痛苦。
VBA 使用一个 Excel 特定语句的示例
Sub Export_All()
Dim fs As Object
Dim aiRef As Object
Dim docRef As Object
Dim jpegExportOptions As Object
Dim f As Object
Dim p As String
Set 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 like
For Each 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 = Nothing
End If
Next
' Note that AI is still open and invisible
End Sub
这里是 javascript 代码,它将 selected 文件夹中的所有 ai 文件导出为 jpg。此代码将要求您 select 一个文件夹。所以 select 文件夹将有 700 个文件
脚本 1:使用 JPEGQuality
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
for (var j = 0; j < activeDocument.artboards.length; j++) {
var activeArtboard = activeDocument.artboards[0];
activeDocument.artboards.setActiveArtboardIndex(j);
var fileName = activeDocument.name.split('.')[0] + "Artboard" + (j + 1) + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
var type = ExportType.JPEG;
var options = new ExportOptionsJPEG();
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;
}
}
因为每个 ai 文件中有两个画板。它将为每个画板创建两个单独的 jpg。您可以根据需要更改 jpg 图片的文件名和文件夹位置。
脚本 2:通过更改分辨率
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
var fileName = activeDocument.name.split('.')[0] + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
// Export Artboard where you can set resolution for an image. Set to 600 by default in code.
var opts = new ImageCaptureOptions();
opts.resolution = 600;
opts.antiAliasing = true;
opts.transparency = true;
try {
activeDocument.imageCapture(new File(destinationFile), activeDocument.geometricBounds, opts);
} catch (e) {
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
currentFile = null;
}
}
对于脚本 2,无论画板如何,一个 ai 文件将只有一个文件。
所以你可以 运行 为你的工作编写脚本并继续。
这是根据您的要求编写的脚本。我刚刚更新了脚本 1 以满足您的要求。默认情况下,它假定标尺以点为单位并将其转换为英寸并在文件名中使用。您可以添加更多检查来处理其他标尺单位。如果画板不超过 26 个,这将有 a-z,如果画板超过 26 个,它将显示其他内容。为此使用 ASCII 码
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
var codeStart = 97; // for a;
for (var j = 0; j < activeDocument.artboards.length; j++) {
var activeArtboard = activeDocument.artboards[j];
activeDocument.artboards.setActiveArtboardIndex(j);
var bounds = activeArtboard.artboardRect;
var left = bounds[0];
var top = bounds[1];
var right = bounds[2];
var bottom = bounds[3];
var width = right - left;
var height = top - bottom;
if (app.activeDocument.rulerUnits == RulerUnits.Points) { //Add more if for more conversions
width = width / 72;
height = height / 72;
}
var fileName = activeDocument.name.split('.')[0] + "-" + String.fromCharCode(codeStart) + "-" + width + "x" + height + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
var type = ExportType.JPEG;
var options = new ExportOptionsJPEG();
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;
}
}
任何人都可以帮我为 illustrator CC2017 编写一个脚本,将文件导出到 Web(旧版)为 JPG,然后保存文件并在之后关闭。我有 700 个文件,每个文件有 2 个艺术板,单击文件>导出>保存为 Web(旧版)然后正确的文件名并保存文件然后关闭会很痛苦。
VBA 使用一个 Excel 特定语句的示例
Sub Export_All()
Dim fs As Object
Dim aiRef As Object
Dim docRef As Object
Dim jpegExportOptions As Object
Dim f As Object
Dim p As String
Set 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 like
For Each 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 = Nothing
End If
Next
' Note that AI is still open and invisible
End Sub
这里是 javascript 代码,它将 selected 文件夹中的所有 ai 文件导出为 jpg。此代码将要求您 select 一个文件夹。所以 select 文件夹将有 700 个文件
脚本 1:使用 JPEGQuality
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
for (var j = 0; j < activeDocument.artboards.length; j++) {
var activeArtboard = activeDocument.artboards[0];
activeDocument.artboards.setActiveArtboardIndex(j);
var fileName = activeDocument.name.split('.')[0] + "Artboard" + (j + 1) + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
var type = ExportType.JPEG;
var options = new ExportOptionsJPEG();
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;
}
}
因为每个 ai 文件中有两个画板。它将为每个画板创建两个单独的 jpg。您可以根据需要更改 jpg 图片的文件名和文件夹位置。
脚本 2:通过更改分辨率
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
var fileName = activeDocument.name.split('.')[0] + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
// Export Artboard where you can set resolution for an image. Set to 600 by default in code.
var opts = new ImageCaptureOptions();
opts.resolution = 600;
opts.antiAliasing = true;
opts.transparency = true;
try {
activeDocument.imageCapture(new File(destinationFile), activeDocument.geometricBounds, opts);
} catch (e) {
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
currentFile = null;
}
}
对于脚本 2,无论画板如何,一个 ai 文件将只有一个文件。 所以你可以 运行 为你的工作编写脚本并继续。
这是根据您的要求编写的脚本。我刚刚更新了脚本 1 以满足您的要求。默认情况下,它假定标尺以点为单位并将其转换为英寸并在文件名中使用。您可以添加更多检查来处理其他标尺单位。如果画板不超过 26 个,这将有 a-z,如果画板超过 26 个,它将显示其他内容。为此使用 ASCII 码
var folder = Folder.selectDialog();
if (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
app.open(currentFile);
var activeDocument = app.activeDocument;
var jpegFolder = Folder(currentFile.path + "/JPG");
if (!jpegFolder.exists)
jpegFolder.create();
var codeStart = 97; // for a;
for (var j = 0; j < activeDocument.artboards.length; j++) {
var activeArtboard = activeDocument.artboards[j];
activeDocument.artboards.setActiveArtboardIndex(j);
var bounds = activeArtboard.artboardRect;
var left = bounds[0];
var top = bounds[1];
var right = bounds[2];
var bottom = bounds[3];
var width = right - left;
var height = top - bottom;
if (app.activeDocument.rulerUnits == RulerUnits.Points) { //Add more if for more conversions
width = width / 72;
height = height / 72;
}
var fileName = activeDocument.name.split('.')[0] + "-" + String.fromCharCode(codeStart) + "-" + width + "x" + height + ".jpg";
var destinationFile = File(jpegFolder + "/" + fileName);
var type = ExportType.JPEG;
var options = new ExportOptionsJPEG();
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;
}
}