Ok, so I found this awesome set of functions for making color swatches that checks to see if it exists first and then just uses the existing one if it does.
But I have run into an issue where the swatch is in use because the color exists in a PDF that I have placed in my document. So when it checks to see if it is there that works fine, till it tries to do the getByName() ... then it cant access it like that for some reason. So I just get an error and it crashes illustrator.
function makeSwatch( swName, swCol) { var doc = app.activeDocument; var sel = doc.selection; if (!this.inCollection(doc.swatches, swName)) { var aSwatch = doc.spots.add(); aSwatch.name = swName; aSwatch.color = swCol; aSwatch.tint = 100; aSwatch.colorType = ColorModel.SPOT; var aSwatchSpot = new SpotColor(); aSwatchSpot.spot = aSwatch; return aSwatchSpot; }else{ return doc.swatches.getByName(swName); } }; function cmykColor(c, m, y, k) { var newCMYK = new CMYKColor(); newCMYK.cyan = c; newCMYK.magenta = m; newCMYK.yellow = y; newCMYK.black = k; return newCMYK; }; function inCollection(collection, nameString) { var exists = false; for (var i = 0; i < collection.length; i++) { if (collection[i].name == nameString) { exists = true; } } return exists; };
Any ideas of how to get around this or what I might be doing wrong would be much appreciated!
Boyd