Get SpotColor tint color

AiScripts
2 min readAug 8, 2022

--

You can get the values of the global or spot color using the spot.getInternalColor() method. The problem with the method is that it sometimes gives fractional values, which you have to round up. Another way is to get a spot.color object and read the RGB or CMYK channels from it.

Tints have only percentage values of 0–100. The tint color value is unknown until you manually convert the tint in the Color panel to RGB or CMYK.

The color values are the same for different the spot tint

Parsing method

The global color tint in Illustrator is created by linear interpolation. It is like a gradient from white to a given color. Therefore, an interpolation function is sufficient to find the value.

function lerp(start, end, t) {
return start + (end - start) * t;
}

What arguments do we have

  • start — 0% tint (always white),
  • end — 100% spot color value
  • t — percentage in the range 0–1

You have to loop each color channel as an argument to the function.

Sample script

var isRgbDoc = activeDocument.documentColorSpace === DocumentColorSpace.RGB,
start, end = selection[0].fillColor,
tintVal = []; // Array for color information
if (end.typename === 'SpotColor') { // Script parse spot colors
// Initialize the starting white color
if (isRgbDoc) {
start = new RGBColor();
start.red = 255;
start.green = 255;
start.blue = 255;
} else {
start = new CMYKColor();
start.cyan = 0;
start.magenta = 0;
start.yellow = 0;
start.black = 0;
}
var t = end.tint / 100;
end = end.spot.color;
// Apply lerp() to each channel in the color object
for (var key in end) {
if (typeof end[key] === 'number') {
tintVal.push( lerp(start[key], end[key], t) );
}
}
alert(isRgbDoc ? 'RGB : ' + tintVal : 'CMYK : ' + tintVal);
}
function lerp(start, end, t) {
return start + (end - start) * t;
}
Parsing tint color

You can also round the values obtained in lerp(), as Illustrator does in the Color panel.

--

--

AiScripts
AiScripts

Written by AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts

No responses yet