导出用于illustrator的脚本以保存为Web jpg [英] Export script for illustrator to save for web jpg

查看:246
本文介绍了导出用于illustrator的脚本以保存为Web jpg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我为Illustrator CC2017编写一个脚本,该脚本以JPG格式将文件导出到网络(旧版),然后保存文件,然后关闭.我有700个文件,每个文件有2个画板,单击File> Export> Save For Web(旧版),然后右键单击文件名并保存文件,然后关闭即可.

Can anyone help me write a script for illustrator CC2017 that Export files to web (legacy) as JPG then save the file and close after. I have 700 files each with 2 art boards and it would be painful to click file>Export>Save For Web(legacy) then right the file name and save the file then close.

推荐答案

以下是根据您的要求编写的脚本.我刚刚更新了脚本1以符合您的要求.默认情况下,它假定标尺以磅为单位,并将其转换为英寸,然后在文件名中使用.您可以添加更多支票以处理其他标尺单元.如果画板数不超过26,则画线为a-z,如果画板数大于26,则显示其他内容.为此使用ASCII代码

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

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的脚本以保存为Web jpg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆