首页 > 解决方案 > 尝试创建一个插画脚本来填充所选内容的颜色并将其导出为样本组中的每种颜色

问题描述

正如标题所说,我已经拼凑起来并将自己的代码编写到您在下面看到的这个怪物中。自从我做任何编码以来已经过去了三年,我的主要工作是图形设计,所以请原谅马虎的编码工作。我想要完成的是让脚本在样本中运行并将填充颜色应用于屏幕上选择的内容,然后为每种颜色导出一个 .png 文件,并将文件名作为样​​本的颜色。

一切似乎都在使用脚本,除了它没有应用填充颜色。它将导出甚至重命名样本组中每种颜色的文件,但它们都导出相同的默认颜色,所以我不相信选择被填充。谁能告诉我我的代码有什么问题?如果我能让这段代码工作,它将把不合理的工作量转化为更易于管理的工作。

谢谢!

#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 fill colour based on the current swatch colour

   mySelection.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();
}

标签: javascriptscriptingadobejsxadobe-illustrator

解决方案


推荐阅读