Copy link to clipboard
Copied
I have a simple script which is attempting to add a swatch. However, it is throwing "Error 1200: an Illustrator error occurred: 1312914990 ('NA~.') Line: 18 -> newSpot.colorType = ColorModel.SPOT;" This is an example taken straight from the docs, the only change I have made is that I am getting my CMYK values from an object (colors). Also, when I hard-code the values for the CMYK values, it works.
function main(argv) {
addSwatch('Black');
}
var colors = {"Black": {"c": 0, "m": 0, "y": 0, "k": 100}};
function addSwatch(color) {
var newSpot = activeDocument.spots.add();
var newColor = new CMYKColor();
newColor.cyan = colors[color].c;
newColor.magenta = colors[color].m;
newColor.yellow = colors[color].y;
newColor.black = colors[color].k;
newSpot.name = color;
newSpot.colorType = ColorModel.SPOT;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
}
main();
You had it fine, you just can't name it "Black". addSwatch('black'); will work but not addSwatch('Black');
Copy link to clipboard
Copied
It was something with the order in which you do this process.
function addSwatch(color) {
var newSpot = activeDocument.spots.add();
newSpot.colorType = ColorModel.SPOT;
var newColor = new CMYKColor();
newColor.cyan = colors[color].c;
newColor.magenta = colors[color].m;
newColor.yellow = colors[color].y;
newColor.black = colors[color].k;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
newSpotColor.name = color;
}
I guess after you assign the spot a color model, you can't give it a name, so you give the name to the swatch-spot-color-thing-object which was created with new SpotColor() and had your spot assigned to it.
Scratch that, it's not putting the name on it.
Copy link to clipboard
Copied
This should probably be reflected in the documentation as well because it is currently how I had it:
Creating a new spot color
// Creates a new spot color in the current document, then applies an 80% tint to the
color
if ( app.documents.length > 0 ){
var doc = app.activeDocument;
// Create the new spot
var newSpot = doc.spots.add();
// Define the new color value
var newColor = new CMYKColor();
newColor.cyan = 35;
newColor.magenta = 0;
newColor.yellow = 50;
newColor.black = 0;
// Define a new SpotColor with an 80% tint
// of the new Spot's color. The spot color can then
// be applied to an art item like any other color.
newSpot.name = "Pea-Green";
newSpot.colorType = ColorModel.SPOT;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
newSpotColor.tint = 80;
}
Copy link to clipboard
Copied
Oh DUH!! Haha you just can't use "Black" as a color name.. reserved.
Copy link to clipboard
Copied
You had it fine, you just can't name it "Black". addSwatch('black'); will work but not addSwatch('Black');
Copy link to clipboard
Copied
Good catch! Thanks for your help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now