该脚本有效,但是在通过色板颜色进行导出之前,插画家会将笔划大小重置为默认值。有谁知道为什么以及如何解决此问题?
#target illustrator
//get a reference to the the current document
var doc = app.activeDocument;
var mySelection = doc.selection;
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
//go through the swatches
for(var i = 0; i < swatches.length; i++){
//set the stroke colour based on the current swatch colour
for(var j=0; j<mySelection.length; j++) { mySelection[j].strokeColor = 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();
}
当您循环遍历画板上的每个选定项目时,您需要检查所循环的当前色板是否未命名为“ [None]
”。
仅当当前色板不是命名为“ [None]
”时才更改笔划颜色。
例如;您需要将当前脚本中的for
循环部分改为以下内容:
// ...
// go through the swatches
for(var i = 0; i < swatches.length; i++){
var swatchName = doc.swatches[i].name;
// Loop through the document selections
for(var j = 0; j < mySelection.length; j++) {
// Change stroke color only when the current swatch is not named [None]
if (swatchName !== "[None]") {
mySelection[j].strokeColor = doc.swatches[i].color;
}
}
doc.exportFile( new File( savePath+ '/' + swatchName + '.png'), ExportType.PNG24, pngExportOpts );
}