Copy link to clipboard
Copied
(CS5, Actionscript)
Hi all,
I have an InDesign document containing TextFrames whose border colors are specified as a CMYK array.
I would like to be able to get its color specification as its closest RGB equivalent.
Does the InDesign DOM contain a method for doing this for me automatically? If not, what workarounds are there?
TIA,
mlavie
Change the color space from ColorSpace.CMYK to ColorSpace.RGB, and ID will do the conversion for you.
Of course this changes the applied colour, so don't forget to reset it back to CMYK when you're done reading.
Copy link to clipboard
Copied
Change the color space from ColorSpace.CMYK to ColorSpace.RGB, and ID will do the conversion for you.
Of course this changes the applied colour, so don't forget to reset it back to CMYK when you're done reading.
Copy link to clipboard
Copied
Ah. This seems to need an addendum.
"ColorSpace" is only available for swatches, it doesn't work directly with 'strokeColor'. So you have to change & examine the applied swatch instead.
Caveat #2 is that if you change CMYK to RGB, read your values, and then change back to CMYK, yo might get different CMYK values! Conversion between CMYK and RGB is not reversible, as color science is not really an accurate science.
So you'll have to work on a copy of your swatch, or use Undo after the change, or close your document without saving.
Copy link to clipboard
Copied
sort of on the same subject.. i have to make a function sort of like this:
covertColor =function(/*int*/Red,/*int*/Green,/*int*/Blue)
{
//make conversions somehow
return {cmyk:[C,M,Y,K],
gray:PrecentGray}
}
Haven't had time yet to get on it, as i'm still working on other, more urgent parts of the script, but if anyone has something like this already done, and doesn't mind sharing it, i would be grateful.
Thank you
Copy link to clipboard
Copied
Here's how to convert RGB to CMYK:
function rgb2CMYK (r,g,b){
var color = app.documents[0].colors.add({space:ColorSpace.RGB,colorValue:[r,g,b]});
color.space = ColorSpace.CMYK;
var retVal = color.colorValue;
color.remove();
return retVal;
}
The same idea for the reverse.
For info on converting to grayscale, check out this:
http://in-tools.com/article/scripts-blog/convert-colors-to-grayscal-in-indesign/
HTH,
Harbs
Copy link to clipboard
Copied
Thank you harbs. very informative and very very helpful.
Copy link to clipboard
Copied
Thanks to Jongware and Harbs. !
I can't believe the solution was so simple - I guess I was expecting some big, bloated .convertColorSpace() method somewhere with a zillion poorly documented parameters...
mlavie