Skip to main content
Participant
January 13, 2015
Answered

Calling for objects with specific CMYK values?

  • January 13, 2015
  • 1 reply
  • 1298 views

Hello,

I'm trying to build a script that searches for paths that have specific CMYK values within a document and then edits the opacity of that path. I can specify for it to look only for objects that have a CMYK color but get nothing once I try to specify the CMYK values I'm looking for.

Additionally, do I need to specify that the output will be a "new CMYKColor", or will it suffice to say "paths.fillColor.back = 100.0", for example, in the output. Here's what I have for this particular function:

var docRef = app.activeDocument;

var paths = docRef.pathItems;

for (i=0; i< paths.length; i++) {

if (paths.fillColor.typename == "CMYKColor" ) {

if (paths.fillColor.cyan == 0.0 &&

paths.fillColor.magenta == 0.0 &&

paths.fillColor.yellow == 0.0 &&

paths.fillColor.black == 20.0 &&

paths.opacity == 100.0) {

var NewColor = new CMYKColor ();

NewColor.cyan = 0.0;

NewColor.magenta = 0.0;

NewColor.yellow = 0.0;

NewColor.black = 100.0;

paths.opacity = 20;

}

else {

alert ("Object(s) not recognized.")

}

}

else {

alert ("Object not CMYK.")

}

}

Thank you.

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi Silly-V,

no, thats's not odd.

Illustrator is a little bit crazy. The most values should be rounded when reading. (like in this thread: Re: Working on a script that will add a new artboard and delete the old one if it is not a specific size)

And so Luis Oyola can do something like that:

var docRef = app.activeDocument;

var paths = docRef.pathItems;

for (i=0; i< paths.length; i++) {

    if (paths.fillColor.typename == "CMYKColor" ) {

        if (Math.round(paths.fillColor.cyan) == 0.0 &&

            Math.round(paths.fillColor.magenta) == 0.0 &&

            Math.round(paths.fillColor.yellow) == 0.0 &&

            Math.round(paths.fillColor.black) == 20.0 &&

            Math.round(paths.opacity) == 100.0) {

                paths.fillColor.black = 100;

                paths.opacity = 20;

                } else {

                    alert ("Object(s) not recognized.");

                    }

                } else {

                    alert ("Object not CMYK.");

                    }

                }

Have fun

1 reply

Silly-V
Legend
January 13, 2015

That's odd, I get on a 20% black cmyk path:
alert(doc.pathItems[0].fillColor.black); // 20

But

alert(doc.pathItems[0].fillColor.black == 20);  // false

And

alert(doc.pathItems[0].fillColor.black > 19 && doc.pathItems[0].fillColor.black < 21); // true

So, I don't know what's up there, but if you can take rounding into your own hands,

alert(Math.round(doc.pathItems[0].fillColor.black) == 20); // true

This is AI CC2014 on Windows

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
January 13, 2015

Hi Silly-V,

no, thats's not odd.

Illustrator is a little bit crazy. The most values should be rounded when reading. (like in this thread: Re: Working on a script that will add a new artboard and delete the old one if it is not a specific size)

And so Luis Oyola can do something like that:

var docRef = app.activeDocument;

var paths = docRef.pathItems;

for (i=0; i< paths.length; i++) {

    if (paths.fillColor.typename == "CMYKColor" ) {

        if (Math.round(paths.fillColor.cyan) == 0.0 &&

            Math.round(paths.fillColor.magenta) == 0.0 &&

            Math.round(paths.fillColor.yellow) == 0.0 &&

            Math.round(paths.fillColor.black) == 20.0 &&

            Math.round(paths.opacity) == 100.0) {

                paths.fillColor.black = 100;

                paths.opacity = 20;

                } else {

                    alert ("Object(s) not recognized.");

                    }

                } else {

                    alert ("Object not CMYK.");

                    }

                }

Have fun

Silly-V
Legend
January 15, 2015

OH NO!  The horror!  I just got back some cards from Vistaprint which looked a whole lot lighter than the ones we ordered at my new job last year when they were still using CS3.  We since upgraded to CC. I thought it was ridiculous because the CMYK values in my UI looked like the exact same numbers.  Then, I put 2 color shapes from both files (the original, old order from last year made by CS3  and the new one that was made in CC) and while they showed the same numbers (0,100,96,28), when both were selected, the fill-color showed a question mark.

I ran this following test script in my CC (we do not have the old CS3 anymore), to my shock I saw a result I was not expecting!

#target illustrator

function test(){

    var doc = app.activeDocument;

    doc.selection = null;

    var clr = new CMYKColor;

    clr.cyan = 0;

    clr.magenta = 100;

    clr.yellow = 96;

    clr.black = 28;

   

    var path = doc.pathItems.ellipse(0,0,100,100);

    path.filled = true;

    path.stroked = false;

    path.fillColor = clr;

    path.selected = true;

    $.write(doc.selection[0].fillColor.cyan+"\r"+doc.selection[0].fillColor.magenta+"\r"+doc.selection[0].fillColor.yellow+"\r"+doc.selection[0].fillColor.black);

}

test();

You can see where I am setting the numbers, right there!  And yet my result is:

0

100

95.9999978542328

28.0000001192093

I am at my wit's end, pixxxel schubser  ,  how can I be sure that I am setting a reliable CMYK set of values anymore?  Why is this craziness happening?  All my life has been a lie, I don't know who to trust anymore!