The fillColor
of an object is always reported as a Swatch
, even if it's not in the Swatches list. The first test to perform is if it is a Color
; you can use instanceof
or hasOwnProperty
for that. A next sane test is if the color space is CMYK.
A Gradient
, as asked in the comment, is slightly more complicated. It contains a list of gradientStops
, and each one has a stopColor
(a simple color or a mixedink) and a location. If it's a simple color, you can retrieve its value as with a plain fill.
if (app.documents.length && app.selection.length >= 1 && app.selection[0].hasOwnProperty('fillColor'))
{
swatch = app.selection[0].fillColor;
if (swatch instanceof Color &&
swatch.space == ColorSpace.CMYK)
alert ("color: "+swatch.colorValue.join(','));
else if (swatch instanceof Gradient)
{
list = [];
for (i=0; i<swatch.gradientStops.length; i++)
if (swatch.gradientStops[i].stopColor instanceof Color)
list.push (i+' = '+swatch.gradientStops[i].stopColor.colorValue.join(','));
else
list.push (i+' = ?');
alert ("gradient:\r"+list.join('\r'));
}
}