Copy link to clipboard
Copied
For example I would like to make my images layer Green and my copy layer Red in my layers palette.
Copy link to clipboard
Copied
The RGB selected highlight colors?
Copy link to clipboard
Copied
In the layers palette whne you create multiple layers each layer is assigned a color by default. I'm looking to change the color for each layer using script. See attched screen grab. I want to change the colors of the layers within the layers palette.
Copy link to clipboard
Copied
If you have a doc open then you can do this… It will look for a layer by name but you can change that to index or whatever…
#target illustrator
var doc = app.activeDocument;
var lay, layCol;
try {
lay = doc.layers.getByName( 'Copy' );
layCol = new RGBColor();
layCol.red = 255;
layCol.green = 0;
layCol.blue = 255;
lay.color = layCol
} catch (e) {};
Copy link to clipboard
Copied
Thanks much. Appreciate your help
Copy link to clipboard
Copied
Actually one more question. There is a drop down menu that contains pre loaded colors. These colors have specific names. Is there a way to change them to the colors within the drop down menu instead of assinging a generic RGB color?
Thanks
Copy link to clipboard
Copied
Im not sure but don't think so… Think they will all be 'other' no matter what the values… ID does have enumerators for it's UI colors but no such luck here…
Copy link to clipboard
Copied
Thanks much helpful. Pls let me know how to change its sub layers color too.
Copy link to clipboard
Copied
A recursive call a function.
New
Something like this:
//@target illustrator
(function recolLays(lays) {
for (var i = 0; i < lays.length; i++) {
if (lays.layers.length) recolLays(lays.layers);
lays.color = _getRandRgb();
}
function _getRandRgb() {
var rgbCol = new RGBColor();
rgbCol.red = __randInt(0, 255);
rgbCol.green = __randInt(0, 255);
rgbCol.blue = __randInt(0, 255);
return rgbCol;
function __randInt(min, max) {
var rand = min + Math.random() * (max + 1 - min);
rand = Math.floor(rand);
return rand;
}
}
}(activeDocument.layers));
Copy link to clipboard
Copied
But after breaking symbols am running this script but this doesn't works over there.
Copy link to clipboard
Copied
Hmm, now I'm executed the script after breaking symbols – it works in CS5. What exactly isn't working?
New
Updated
But this is only an example of recursion. And what exactly do you want, I do not know.
Copy link to clipboard
Copied
Yeah am working in CC 2017. The layer color was changed using this script buut its sublayers colors doesnt.
Copy link to clipboard
Copied
Give me your .ai-files where this doesn't working. What your OS? Are you use my unmodified version of script from this post ?
I'm tested it in cc 2017 - with multiple (and multiple and multiple...) sub-layers ... all layers and sublayers recolored by script. I'm don't know why you have a problem with.