Skip to main content
Lordrhavin
Inspiring
June 12, 2025
Question

How do swatch / colormodels actually work?

  • June 12, 2025
  • 2 replies
  • 174 views

the properties of  CMYK-color are pretty staight forward:

swatch.colorValue = [33,33,33,100];
swatch.name = "richblack";
swatch.space = "CMYK";
swatch.model = "PROCESS";

That is a CMYK richblack called swatch with the CMYK-values (33/33/33/100).

 

When I setup a spotcolor HKS  4 K, it looks like this:

swatch.name = "HKS 4 K";
swatch.space = "CMYK";
swatch.model = "SPOT";

As you can see, it has no color value. Why is this, is there another collection where I can get those? I mean: yes, it is a spot color. But it still needs simulation colors (CMYK or RGB) onscreen, right?

 

The reason why I'm asking is: Lets say I have a table of colors with LAB, CMYK and RGB-values. Now I want to programmatically pollute the swatches in my active Document with a bunch of spot colors. Lets say we have...

var name = "HKS 4 K";
var cmyk = [0,20,100,0];


How can I:
- if that color is already known, but not a swatch of the current document

--> add it.

- If that color is unknown

--> add it and give it the given CMYK simulation colors? 

2 replies

rob day
Community Expert
Community Expert
June 12, 2025

- if that color is already known, but not a swatch of the current document

 

You can get a list of unnamed colors with something like this:

 

var un = d.colors.everyItem().getElements()
for (var i = 0; i < un.length; i++){
    if (un[i].name == "") {
        $.writeln(un[i].space.toString() + "  " + un[i].colorValue)
    } 
};

 

rob day
Community Expert
Community Expert
June 12, 2025

HI @Lordrhavin, You’ll have to use the color collection not swatch. Here I have a helper function to check if a named color already exists:

 

 

 

var d = app.activeDocument

var c = makeSwatch(d, "HKS 4 K")
c.properties = {model:ColorModel.SPOT, space:ColorSpace.LAB, colorValue:[84,9,93]}

var r = makeSwatch(d, "richblack")
r.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[33,33,33,100]}


/**
* Makes a new named Swatch 
* @ param the document to add the color to 
* @ param color name 
* @ return the new swatch or existing swatch with name
*/

function makeSwatch(d, n){
    if (d.colors.itemByName(n).isValid) {
        return d.colors.itemByName(n);
    } else {
        return d.colors.add({name:n});
    }
}