javascript 是否可以为photoshop创建一个脚本,将文件中所有颜色层的颜色更改为随机颜色?

neekobn8  于 2023-02-02  发布在  Java
关注(0)|答案(2)|浏览(175)

我正在尝试创建一个脚本,可以改变我的文件中的所有颜色层的颜色为随机颜色,然后将文件导出为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)
myzjeezk

myzjeezk1#

LayerKind.COLOR看起来不是thing

qhhrdooz

qhhrdooz2#

return color将只返回对象。您需要返回颜色color.rgb.hexValue的值

相关问题