为illustrator导出脚本以保存为web jpg

时间:2017-08-30 21:33:54

标签: javascript export jpeg adobe-illustrator

任何人都可以帮我写插画家CC2017的脚本,将文件导出为web(旧版),然后保存文件并关闭。我有700个文件,每个文件有2个艺术板,单击文件>导出>保存为Web(旧版)然后右键文件名然后保存文件然后关闭将是痛苦的。

3 个答案:

答案 0 :(得分:2)

以下是将所选文件夹中存在的所有ai文件导出为jpg的javascript代码。此代码将要求您选择一个文件夹。所以选择将有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 :(得分:1)

根据您的要求,这是脚本。我刚刚更新了脚本1以符合您的要求。默认情况下,它假定标尺位于Points中并将其转换为英寸并在文件名中使用。您可以添加更多检查来处理其他标尺单位。如果画板不超过26,如果画板超过26,则会有a-z,它会显示其他内容。使用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;
    }
}

答案 2 :(得分:0)

使用一个特定于Excel的语句的VBA示例

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