How to put swatches in a swatchGroup using javascript?
I can't figure this out for the life of me.
I have these functions that work great. It puts the SpotColor swatches into the swatch panel.
var doc = app.activeDocument;
var paths = doc.pathItems;
function getColorNumbers() {
var colorNums = []
for (i = 0; i <= 10; i += 1) {
colorNums.push(i / 100);
}
for (i=0;i<colorNums.length;i++) {
createNewSpotColor(colorNums);
}
return colorNums;
}
function createNewSpotColor(color) {
//Define the new color value
var newColor = new CMYKColor();
newColor.cyan = 0;
newColor.magenta = 0;
newColor.yellow = 0;
newColor.black = color;
//Create the new spot
var newSpot = app.activeDocument.spots.add();
//Define the new SpotColor
newSpot.name = color.toString();
//newSpot.tint = 0;
newSpot.typename = SpotColor;
newSpot.color = newColor;
// create a spotcolor object
newSpot.colorType = ColorModel.SPOT;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
//newSpotColor.tint = 0;
}
getColorNumbers();
Now I would like to put these swatches into a swatchGroup. I've tried several things. One of my tries worked but put every individual swatch into it's own swatchGroup. All the other times I can get the swatches in the panel and a new swatchGroup added, but can't get the swatches in the swatchGroup.
var doc = app.activeDocument;
var colorgroup = doc.swatchGroups.add();
colorgroup.name = 'Cad colors';
var selSwatch = doc.swatches.getSelected();
var swatch = doc.swatches;
for (a=0; a<swatch.length; a++) {
if (swatch.color == SpotColor) {
swatch.selected = true;
if(swatch.selected == selSwatch) {
colorgroup.addSpot(selSwatch);
}
}
}
What am I missing?
