I am trying to create a script that can change the color of all the color layers in my file to a random color and then exportt the file as a PNG.
I have already tried this code
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;
but it gives me the following error:
1320 Invalid enumeration value Line 19
if (layer.kind === LayerKind.COLOR || layer.kind === LayerKind.NORMAL)
2
Answers
LayerKind.COLOR
doesn’t appear to be a thing.return color
will just return the object. You need to return the value of the colourcolor.rgb.hexValue