javascript - 尝试创建一个插画脚本来填充所选内容的颜色并将其导出为样本组中的每种颜色
问题描述
正如标题所说,我已经拼凑起来并将自己的代码编写到您在下面看到的这个怪物中。自从我做任何编码以来已经过去了三年,我的主要工作是图形设计,所以请原谅马虎的编码工作。我想要完成的是让脚本在样本中运行并将填充颜色应用于屏幕上选择的内容,然后为每种颜色导出一个 .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();
}
解决方案
推荐阅读
- typescript - 如何在 Svelte 文件中转换 Typescript 常量枚举?
- c++ - 为什么延长寿命在这里的工作方式不同?
- node.js - 使用 sequelize newCourse.setCategory 不是函数
- react-admin - 有没有办法自定义datagrid的表头?
- windows - 浏览器视口宽度是否始终取决于 Windows 10 缩放设置?
- swift - 如何在 Swift 中关闭和完成处理程序后获取数据
- javascript - Is there a way to create a JSON file using discord.js v12?
- flutter - 模拟器上的应用程序运行完美,但在真实设备上运行时,位置标记不可见,并且在运行代码时显示无法加载资产
- c# - 需要使用正则表达式用“,”而不是“\”来分割字符串
- latex - 如何减少位于其他节点之上的 2 个节点之间的空间?