Skip to main content
aiScripting
Inspiring
September 4, 2015
Answered

Spot Color conflict Placed PDF

  • September 4, 2015
  • 2 replies
  • 1688 views

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.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

This topic has been closed for replies.
Correct answer Silly-V

Really!?

so here is the code where I am calling out the function:

    //hole color

    var holeColorCMYK = cmykColor (50, 0, 100, 0)

    // Hole Spot Object

    var holeColorSPOT = makeSwatch("CutContourRte_In", holeColorCMYK);

var TLhole = aLayer.pathItems.ellipse(tHsTop,lHsLeft,holeSize,holeSize);

TLhole.filled = false;

TLhole.strokeWidth = 1;

TLhole.strokeColor = holeColorSPOT;

I could send you a file that I was testing with too... to see if you are having the same issue.

Also I should note that I am using CC2015

-Boyd


Hey, I checked your code out and tweaked a few things, and got it to work. Go ahead and test it- fingers crossed. Your make swatch function, methinks has a problem of returning two different things: a SpotColor or a Swatch object.. So, I made it use for the fillColor, the Swatch.color, and it's working for me. I hope that this too resolves your problem of placed PDFs.

#target illustrator-19

function test(){

    function makeSwatch(swName, swCol) {  

        var doc = app.activeDocument;

        if(!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 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.name == nameString){  

                exists = true;  

            }  

        }  

        return exists;  

    };

  

    var doc = app.activeDocument;

    var holeSize = 50;

    var tHsTop = -100;

    var lHsLeft = 100;

    var aLayer =doc.layers[0];

    //hole color

    var holeColorCMYK = cmykColor (50, 0, 100, 0);

    // Hole Spot Object

    var holeColorSPOT = makeSwatch("CutContourRte_In", holeColorCMYK);

    var TLhole = aLayer.pathItems.ellipse(tHsTop,lHsLeft,holeSize,holeSize);

    TLhole.filled = false;

    TLhole.strokeWidth = 1;

    TLhole.strokeColor = holeColorSPOT.color;

}

test();

2 replies

aiScripting
Inspiring
September 17, 2015

Hey guys! Thanks so much for all your help on this!

I am wondering if there is a way to access spot colors from a custom color palet?

e.g. I have a custom pallet with swatches that I use all the time. Can I access these from my script?

Thanks!

-Boyd

Qwertyfly___
Legend
September 17, 2015

when you save your "FerrariColor" set of swatches you can save it as .ai.

not sure about mac but in windows the default location it saves in is something like:

C:\Users\USERNAME\AppData\Roaming\Adobe\Adobe Illustrator 19 Settings\en_GB\x64\Swatches

you can open this file with a script and access the swatches from that.

or you could just have the swatches embedded in your script. its only 9 colours so would not be a big deal to have them in your code.

aiScripting
Inspiring
September 17, 2015

Hmm I see,

I guess the reason I was thinking it would be nice to get them from the pallet is I was hoping that I could eliminate the issues I've been having where when it exists in the file then it crashes the script or throws an error in Ai.

The several versions of the makeSwatch(); function kindly supplied by you guys above really should work (and do in most my small tests) but for some reason or another when ever I try to use it in my main script I am working on it has an issue every time! so I am thinking the issue is more to do with my script and the state of the document or something...

My brain hurts! lol (trying to teach my self HTML and plain Javascript too! So I can make real Ai extensions)

Thanks so very much! for your help! its been much appreciated!

-Boyd

Silly-V
Legend
September 4, 2015

Hey, when you say placed PDF, do you mean you placed it with script, in the same instance as running these functions?

aiScripting
Inspiring
September 4, 2015

Hello!

Yes the script places the PDF, but I have tested it with manually placing the PDF and still get the same issue.

-Boyd

Silly-V
Legend
September 4, 2015

That's wild, It seemed to have worked for me, with manually placed PDF.