if (!(colorID in swatchlist)) {
missingswatches[colorID] = colorNodeName;
return;
}
var targetLayerName = tpNodeID + '_' + tpNodeName,
this_doc = app.activeDocument,
this_cw = this_doc.groupItems.getByName(mycw),
myswatch = swatchlist[colorID],
myswatchname = swatchlist[colorID].name,
swatchexists = false,
newswatch;
try {
var checkExistence = this_doc.swatches[myswatchname];
swatchexists = true;
//alert('swatch ' + myswatchname + ' existed');
}
catch (err) {
//alert('swatch ' + myswatchname + ' did not exist');
newswatch = this_doc.swatches.add();
newswatch.name = myswatchname;
newswatch.color = myswatch.color;
newswatch.typename = myswatch.typename;
}
if (swatchexists === true) {
var operateOnTrue = checkPathType(this_cw.pageItems.getByName(targetLayerName));
operateOnTrue.fillColor = this_doc.swatches[myswatchname].color;
} else {
var operateOnFalse = checkPathType(this_cw.pageItems.getByName(targetLayerName));
operateOnFalse.fillColor = newswatch.color;
}
That's a function that I've written to look at certain documents and pull from their swatches. We have a naming system for our swatches and it matches the IDs to determine which one to add.
My problem is that it adds the swatches perfectly fine(both to the item and to the swatch library for the current document with the name, id, and correct information), but then when adding a new swatch, it completely ERASES the swatches in the current document's library, while keeping the color on the layers.
Is there something that I'm doing incorrectly? It seems like a bug in AI more than anything - why would adding a swatch completely wipe out my swatch library?
Thanks.