Skip to main content
Participant
June 26, 2024
Question

Illustrator - javascript to change all layers to same colour

  • June 26, 2024
  • 1 reply
  • 250 views

Hello community,

I have searched everywhere for a script that changes all layers in Illustrator 2024 to the same colour.

The script I found is below but for some reason it doesn't work (no errors appear - just does nothing).

var doc = app.activeDocument;
var layers = doc.layers;
var LightBlueCol = new RGBColor();
LightBlueCol.red = 79;
LightBlueCol.green = 128;
LightBlueCol.blue = 255;
for(vari=0;i<layers.length;i++){
var aLay = layers;
aLay.color = LightBlueCol;
// layers[i].name = LightBlueCol + (layers.length - i).toString();
}
In the example below, I want to change all the Test layers to Light Blue (names of layers don't matter).
Can anyone point me in the right direction please. I am not a coder and am new to this but for the life of me I can't see what the problem is.
Any help would be appreciated.
This topic has been closed for replies.

1 reply

Sergey Osokin
Inspiring
June 27, 2024

When updating the forum, the indexes of array elements disappeared in the old scripts. It was missing var aLay = layers[i].

 

var doc = app.activeDocument;
var layers = doc.layers;
var LightBlueCol = new RGBColor();
LightBlueCol.red = 79;
LightBlueCol.green = 128;
LightBlueCol.blue = 255;
for (var i = 0; i < layers.length; i++) {
  var aLay = layers[i];
  aLay.color = LightBlueCol;
  // aLay.name = LightBlueCol + (layers.length - i).toString();
}

 

Participant
June 27, 2024

Perfect!

Thank you so much Sergey.

I tried changing a few lines myself but don't have enough knowledge of Javascript to make it work.