Skip to main content
rcraighead
Legend
August 13, 2019
Question

Assign fill color to selection?

  • August 13, 2019
  • 1 reply
  • 255 views

Simple, I'm sure, but I'm getting nowhere.

var aDoc = app.activeDocument;

var shape = aDoc.layers["FINGERPRINT"].pathItems[0];

shape.selected = true;

shape.fillColor = "BDBDFF";

app.executeMenuCommand("sendToBack");

"Object Expected" error on line 4. What am I doing wrong?

I'd like to set the color of the selection and send it to back. "SendToBack" works, but I must not understand how to use "fillColor".

This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
August 13, 2019

1. you don't need to select the shape to apply color

2. fillColor property expects a Color Object.

     You can assign a swatch color ie aDoc.swatches[5].color or aDoc.swatches['myRedSwatch'].color

or you can create your own mix, this sample is from the Reference

Setting a CMYK color

// Sets the fill color of the frontmost path item in

// the current document to a light purple CMYK color

if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0) {

frontPath = app.activeDocument.pathItems[0];

// Set color values for the CMYK object

newCMYKColor = new CMYKColor();

newCMYKColor.black = 0;

newCMYKColor.cyan = 30.4;

newCMYKColor.magenta = 32;

newCMYKColor.yellow = 0;

// Use the color object in the path item

frontPath.filled = true;

frontPath.fillColor = newCMYKColor;

}