You might consider creating the document swatches at the top of the script—"C=15 M=100 Y=100 K=0",//RED would break on my InDesign because I’ve customized my default swatches. I don’t think you can be sure the defaults exist.
I use this function for swatch creation, which checks to see if the named swatch exists and if it doesn’t creates one. Note that some color names are reserved and can’t be used for swtches, (e.g. Cyan, Yellow, Magenta)
var graphicTemplate = app.documents.add()
var docCyan = makeSwatch(graphicTemplate, "ProcessCyan")
docCyan.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[100,0,0,0]}
var docRed = makeSwatch(graphicTemplate, "Red")
docRed.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[15,100,100,0]}
var docGreen = makeSwatch(graphicTemplate, "Green")
docRed.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[100,0,100,0]}
// use the color object variable for the fillColor:
//graphicSpecs.lines[1].texts[0].fillColor = docCyan;
/**
* Makes a new named Swatch
* @ param the document to add the color to
* @ param color name
* @ return the new swatch
*/
function makeSwatch(d, n){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n});
}
}
... View more