javascriptadobe-illustrator

Illustrator javascript assign Color Swatch / Spot Color to Path Item


I have a Javascript File which I use in Adobe Illustrator to create a Rectangle with the following Code:

var MyRect = artLayer.pathItems.rectangle( 12, 22, 180, 180 ); 

I have a Color Swatch / Spot Color with the Name "My_Color_01". How can I assign a color swatch and set its tint as a fill color to the rectangle I have created?


Solution

  • Here you go:

    var doc = app.activeDocument;
    var artLayer = doc.layers[0];
    var color = doc.swatches.getByName('My_Color_01').color;
    color.tint = 50; // <-- 50% tint, for example
    var MyRect = artLayer.pathItems.rectangle( 12, 22, 180, 180 );
    MyRect.fillColor = color;