插画家填充颜色对象

illustrator fillcolor object

是否有一个脚本可以遍历每个样本颜色并每次复制 "layer 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();
}

还值得注意的是,您可以 parse .ase (Adobe Swatch Exchange) 文件以选择的语言导出图像,完全避免使用 Illustrator。