• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Trying to create a script that changes the color of specific color layers

New Here ,
Feb 01, 2023 Feb 01, 2023

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);

 

TOPICS
Actions and scripting , Windows

Views

68

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines