Copy link to clipboard
Copied
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.
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 &&
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 ...)
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
![]()
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
In fact, setting the UI colors manually also results in the same read. It used to not do this in previous version, I don't believe it did!
Copy link to clipboard
Copied
does pixxxel's suggestion of using math.round change your result? it would be unfortunate if you had to add that syntax in every time, but that should eliminate those 10 digit decimals and give you the 96% and 28% you're looking for..
Copy link to clipboard
Copied
Will, the strange thing I encountered was that opening the CS3 document, the color inside it reads the rounded numbers, but when creating a new shape and setting those numbers, it always has the decimals.
Copy link to clipboard
Copied
can you use math.round to set the process values?? or does that only work for reading values?
Copy link to clipboard
Copied
Traditionally, when you set something, like var x = 10 ... you don't need to round the already round number. What it looks like, is Illustrator CC takes your nice whole number and for some reason messes it up.
Copy link to clipboard
Copied
you should send adobe an email asking them to fix the issue. then hold your breath until it's fixed. just kidding, don't do that. you'll die.
Copy link to clipboard
Copied
Haha. well this is an interesting thing I previously was not aware of.
Copy link to clipboard
Copied
Actually, please ignore the Vistaprint thing, it's expected to get huge variations in digital print anyways.
Copy link to clipboard
Copied
particularly digital printing thats so cheap..
Copy link to clipboard
Copied
This worked in my situation (sorry for the late reply!). Thank you!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more