Copy link to clipboard
Copied
Hi all,
I'm in desparate need for some help. I think the answer to my question is relatively simple, but I don't have a lot of experience in scripting.
I am trying to create a script that adds custom spot colours to the swatch pallet. I've manage to put together something that works (I've adapted an existing script), but the colours added are not spots, just CMYK colour swatches.
Also, I need the script not to error if the swatch already exists. I've spent days pulling my hair out trying to get this to work, any help would be enormously appreciated.
//Add Custom Swatches
var docRef = app.activeDocument;
function cmykColor(c, m, y, k) {
var newCMYK = new CMYKColor();
newCMYK.cyan = c;
newCMYK.magenta = m;
newCMYK.yellow = y;
newCMYK.black = k;
return newCMYK;
}
with (docRef) {
var a = cmykColor(0, 30, 30, 0);
makeSwatch(docRef, 'Varnish', a);
var a = cmykColor(30, 0, 30, 0);
makeSwatch(docRef, 'Spot White', a);
var a = cmykColor(100, 0, 0, 0);
makeSwatch(docRef, 'Profile', a);
var a = cmykColor(0, 0, 0, 75);
makeSwatch(docRef, 'Cut', a);
var a = cmykColor(37, 0, 15, 0);
makeSwatch(docRef, 'Crease', a);
var a = cmykColor(30, 30, 0, 0);
makeSwatch(docRef, 'Perf', a);
var a = cmykColor(20, 0, 0, 0);
makeSwatch(docRef, 'TECH - Clear Area', a);
var a = cmykColor(30, 0, 0, 30);
makeSwatch(docRef, 'TECH - Text Free', a);
var a = cmykColor(0, 0, 0, 50);
makeSwatch(docRef, 'TECH - Bleed', a);
var a = cmykColor(0, 7, 20, 10);
makeSwatch(docRef, 'TECH - Text Area', a);
}
function makeSwatch(doc, swName, swCol) {
if (!inCollection(doc.swatches, swName)) {
var thisSwatch = doc.swatches.add();
thisSwatch.name = swName;
thisSwatch.color = swCol;
return thisSwatch;
}else{
return doc.swatches.getByName(swName);
}
}
function inCollection(collection, nameString) {
var exists = false;
for (var i = 0; i < collection.length; i++) {
if (collection.name == nameString) {
exists = true;
}
}
return exists;
}
Hello and welcome.
Try this:
...var docRef = app.activeDocument;
var a = cmykColor(0, 0, 0, 50);
makeSwatch( 'TECH - Bleed', a);
a = cmykColor(30, 30, 0, 0);
makeSwatch( 'Perf', a);
a = cmykColor(20, 0, 0, 0);
makeSwatch( 'TECH - Clear Area', a);
function makeSwatch( swName, swCol) {
if (!inCollection(docRef.swatches, swName)) {
var aSwatch = docRef.spots.add();
aSwatch.name = swName;
aSwatch.color = swCol;
aSwatch.tint = 100;
aSwatch.colorType = ColorModel.SPOT;
var aSwatchSpot = new S
Copy link to clipboard
Copied
Hello and welcome.
Try this:
var docRef = app.activeDocument;
var a = cmykColor(0, 0, 0, 50);
makeSwatch( 'TECH - Bleed', a);
a = cmykColor(30, 30, 0, 0);
makeSwatch( 'Perf', a);
a = cmykColor(20, 0, 0, 0);
makeSwatch( 'TECH - Clear Area', a);
function makeSwatch( swName, swCol) {
if (!inCollection(docRef.swatches, swName)) {
var aSwatch = docRef.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 docRef.swatches.getByName(swName);
}
}
function inCollection(collection, nameString) {
var exists = false;
for (var i = 0; i < collection.length; i++) {
if (collection.name == nameString) {
exists = true;
}
}
return exists;
}
function cmykColor(c, m, y, k) {
var newCMYK = new CMYKColor();
newCMYK.cyan = c;
newCMYK.magenta = m;
newCMYK.yellow = y;
newCMYK.black = k;
return newCMYK;
}
Is this right for you?
Copy link to clipboard
Copied
That's fantastic, thanks so much for helping me with this!
Copy link to clipboard
Copied
Good afternoon I'm looking to adapt this script to add, Spot colours AND a CMYK colours. Specifically White and Black. Are you able to assist?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now