Copy link to clipboard
Copied
Hi,
I am trying to get the RGB and CMYK values for all swatches list in document. It is working fine but it show unnecessary paper color. Could you please someone validate where I missed?
var len=app.documents[0].swatches.everyItem().getElements();
for(i=3;i<len.length;i++){
myColor=app.documents[0].colors;
if(myColor.space==ColorSpace.CMYK){
myCMYK (myColor.colorValue[0],myColor.colorValue[1],myColor.colorValue[2],myColor.colorValue[3])
}
else{
myRGB (myColor.colorValue[0],myColor.colorValue[1],myColor.colorValue[2])
}
}
function myRGB (r,g,b){
var color = app.documents[0].colors.add({space:ColorSpace.RGB,colorValue:[r,g,b]});
color.space = ColorSpace.CMYK;
var RGBdummy = color.colorValue;
alert("Swatch Name: \t"+myColor.name+"\t"+"Swatch value: \t"+myColor.colorValue+"\nIts relevant CMYK: "+RGBdummy);
color.remove();
return RGBdummy;
}
function myCMYK (c,m,y,k){
var color = app.documents[0].colors.add({space:ColorSpace.CMYK,colorValue:[c,m,y,k]});
color.space = ColorSpace.RGB;
var CMYKdummy = color.colorValue;
alert("Swatch Name: \t"+myColor.name+"\t"+"Swatch value: \t"+myColor.colorValue+"\nIts relevant RGB: "+CMYKdummy);
color.remove();
return CMYKdummy;
}
Thanks,
K
Should be
myColor=app.documents[0].swatches; |
and not
myColor=app.documents[0].colors; |
Please mark as answered,
Thanks
Trevor
Copy link to clipboard
Copied
Hi Karthi
add before the for
var paperSwatch = app.documents[0].swatches.itemByName('Paper'); |
and after the myColor
if(myColor === paperSwatch) {continue;}
HTH
Trevor
Copy link to clipboard
Copied
Hello Trevor,
Thanks for your reply. It will fix the problem but I am also getting Cyan and Magenta alerts. I am not said this in my previous posting.
1) Please open a new document. It contain default colors.
2) Add one RGB color
3) Run the script
Now you can see the results little strange. I am not sure where it went wrong.
FYI.. In future i am going to use this script with UI.. so if i choose a color from dropdown it will show RGB and respective CMYK valse viceversa.
Thanks,
K
Copy link to clipboard
Copied
So just make an object map of the swatches you don't want, you can use the names
myNotWantedSwatches = {Paper: true, Cyan: true, etc.... }
And then
if (myColor.name in myNotWantedSwatches) {continue;}
Copy link to clipboard
Copied
Hi Trevor,
Yes we can add whatever we need to eliminate. Jus curious to know why it is showing!!
Thanks,
K
Copy link to clipboard
Copied
Should be
myColor=app.documents[0].swatches; |
and not
myColor=app.documents[0].colors; |
Please mark as answered,
Thanks
Trevor
Copy link to clipboard
Copied
Yes it is working, thanks a lot