Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Adding Custom Spot Colours

$
0
0

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[i].name == nameString) {

               exists = true;

          }

     }

     return exists;

}


Viewing all articles
Browse latest Browse all 12845

Trending Articles