我正在尝试创建一个脚本,可以改变我的文件中的所有颜色层的颜色为随机颜色,然后将文件导出为PNG格式。
我已经试过这个代码了
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var activeDocument = app.activeDocument;
var colorLayers = [];
// generate a random color
var randomColor = function() {
var color = new SolidColor();
color.rgb.red = Math.floor(Math.random() * 256);
color.rgb.green = Math.floor(Math.random() * 256);
color.rgb.blue = Math.floor(Math.random() * 256);
return color;
}
// select color layers
for (var i = 0; i < activeDocument.layers.length; i++) {
var layer = activeDocument.layers[i];
if (layer.kind === LayerKind.COLOR || layer.kind === LayerKind.NORMAL) {
colorLayers.push(layer);
}
}
// change color of selected color layers
for (var i = 0; i < colorLayers.length; i++) {
colorLayers[i].adjustColorBalance(100, 0, 0, 0);
colorLayers[i].fill(randomColor());
}
app.preferences.rulerUnits = originalRulerUnits;
但它给出了以下错误:
1320 Invalid enumeration value Line 19
if (layer.kind === LayerKind.COLOR || layer.kind === LayerKind.NORMAL)
2条答案
按热度按时间myzjeezk1#
LayerKind.COLOR
看起来不是thing。qhhrdooz2#
return color
将只返回对象。您需要返回颜色color.rgb.hexValue
的值