illustrator填充颜色对象

illustrator fillcolor object

本文关键字:对象 颜色 填充 illustrator      更新时间:2023-09-26

有没有一个脚本可以循环遍历每个样例颜色,每次它复制"第1层"并用样例颜色填充它?因此,如果样例中有20种颜色,那么将添加20个具有不同颜色的新层。

如果是,每个新层是否可以从样例中获取名称,并导出为swatchName.jpg?

通过Illustrator JavaScript API,您会注意到Document对象有一个样例数组。剩下要做的就是:

  1. 循环浏览每个样例
  2. 绘制当前样例颜色的框
  3. 导出图像

我建议使用png-24而不是jpg来避免压缩伪影。

下面是一个注释脚本,它首先提示导出文件夹:

#target illustrator
//get a reference to the the current document
var doc = app.activeDocument;
//...and it's swatches
var swatches = doc.swatches;
//select a folder to save images into
var savePath = Folder.selectDialog( 'Please select a folder to export swatch images into', '~' );
//exported image dimensions
var width = 100;
var height = 100;
//PNG export options
var pngExportOpts = new ExportOptionsPNG24();
   pngExportOpts.antiAliasing = false;//keep it pixel perfect 
   pngExportOpts.artBoardClipping = false;//use the path's dimensions (setup above), ignore full document size
   pngExportOpts.saveAsHTML = false;
   pngExportOpts.transparency = true;//some swatches might have transparency
//remove strokes
doc.defaultStroked = false;
//go through the swatches
for(var i = 0; i < swatches.length; i++){
   //add a rectangle
   var rect = doc.pathItems.rectangle(0, 0, width, height);  
   //set the fill colour based on the current swatch colour
   rect.fillColor =  swatches[i].color;
   //export png
   doc.exportFile( new File( savePath+ '/' + swatches[i].name + '.png'), ExportType.PNG24, pngExportOpts );
   //remove any previous paths (in case of transparent swatches)
   doc.pathItems.removeAll();
}

同样值得注意的是,您可以用选择的语言解析.ase(Adobe Swatch Exchange)文件来导出图像,从而完全避免使用Illustrator。