Skip to main content
dublove
Legend
June 2, 2026
Question

How to create a new layer with a specific name and set its color in Illustrator?

  • June 2, 2026
  • 1 reply
  • 22 views

This seems to work a little differently than in InDesign.
I can't figure out which line is causing the problem.

var d = app.activeDocument;
var items = d.selection;
var item = d.selection[0];
var sel = items;

//layer name and color
var ln = "Text";
var col = [249, 138, 9];

//If no layer is specified, a new layer will be created.
var myLayer = d.layers.getByName(ln);
var lsl = app.activeDocument.layers.length;
if (!myLayer.isValid) {
var myLayer = app.activeDocument.layers.add({ name: ln, layerColor: col });
}

//move select to myLayer
for (i = 0; i < sel.length; i++) {
sel[i].moveToEnd(myLayer);

}

 

    1 reply

    Monika Gause
    Community Expert
    Community Expert
    June 2, 2026

    You could check out if some of this here works for you: 

     

    dublove
    dubloveAuthor
    Legend
    June 2, 2026

    Hi ​@Monika Gause 

    Is this it? I can't open this website.
    https://www.dropbox.com/scl/fi/rg7i6tgilt7iyspwf99w4/NewLayerColor_-AI26-Release_x64.aip?rlkey=2qmskt3awl5og7msizrygifo9&dl=0

    Monika Gause
    Community Expert
    Community Expert
    June 2, 2026

    I do not know if the script still works, there are other things listed on the thread.