Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding Custom Spot Colours

Guest
Dec 02, 2013 Dec 02, 2013

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;

}

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 02, 2013 Dec 02, 2013

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

...
Translate
Adobe
Community Expert ,
Dec 02, 2013 Dec 02, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 03, 2013 Dec 03, 2013

That's fantastic, thanks so much for helping me with this!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 15, 2017 Sep 15, 2017
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines