Copy link to clipboard
Copied
I am trying to create a script that changes the colour of multiple color layers to a random color.
This is the code I have so far
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var activeDocument = app.activeDocument;
var colorLayers = [];
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;
}
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);
}
}
for (var i = 0; i < colorLayers.length; i++) {
colorLayers[i].adjustColorBalance(100, 0, 0, 0);
colorLayers[i].fill(randomColor());
}
app.preferences.rulerUnits = originalRulerUnits;
When I run this code it spits back error 1320: invalid enumeration value for the code if (layer.kind === LayerKind.COLOR || layer.kind === LayerKind.NORMAL) {
colorLayers.push(layer);
Copy link to clipboard
Copied
If you're filling a solid color adjustment layer, I believe the layerkind is SOLIDCOLOR. I would also use scriptListener and AM code to change the color, as I don't think using fill would work on that type of layer.