Copy link to clipboard
Copied
I had this very useful script years ago and then lost it.
It was posted on InDesignSecrets.com on https://indesignsecrets.com/author/bob-levineNovember 13, 2008 and written by Dave Saunders.
Been looking for a while on the internet and my back-up disks but with no luck.
Does anybody have an inkling where I could lay my hands on it.
Cheers.
His site is not available anymore, but I've found it in my archive:
...//DESCRIPTION: Convert RGB to rounded CMYK
/*
©Copyright Dave Saunders
This script converts RGB colors in the active document or,
if no document is open, in the application default swatches
to CMYK, rounding the values to the nearest whole number
and, if the RGB swatch was originally named in the form
Adobe's Kuler uses, the swatch name is changes to the
CMYK naming format used by InDesign.
*/
(function() {
a script that rounds up or down all cmyk decimal numbers of color (not only swatches) in the document
Try this, note that the conversion numbers depend on your document’s assigned RGB and CMYK profiles:
var c=app.activeDocument.colors;
for (var i = 0; i < c.length; i++){
try {
c[i].space = ColorSpace.CMYK
c[i].colorValue = roundCMYK(c[i].colorValue)
}catch(e) {}
}
/**
* Rounds CMYK values up
* @ param array of CMYK values
* @ return rounded arry
*
*/
function r
...
Copy link to clipboard
Copied
His site is not available anymore, but I've found it in my archive:
//DESCRIPTION: Convert RGB to rounded CMYK
/*
©Copyright Dave Saunders
This script converts RGB colors in the active document or,
if no document is open, in the application default swatches
to CMYK, rounding the values to the nearest whole number
and, if the RGB swatch was originally named in the form
Adobe's Kuler uses, the swatch name is changes to the
CMYK naming format used by InDesign.
*/
(function() {
if (app.documents.length > 0) {
var target = app.documents[0];
} else {
var target = app;
}
var myColors = target.colors.everyItem().getElements();
for (var j = myColors.length - 1; j >= 0; j--) {
if (myColors
.space == ColorSpace.rgb) { convertToCMYK(myColors
); if (myColors
.name.indexOf("R =") != -1) { renameForCMYK(myColors
); }
}
}
function renameForCMYK(color) {
var vals = color.colorValue;
color.name = "C=" + vals[0] + " M=" + vals[1] +
" Y=" + vals [2] + " K=" + vals[3];
}
function convertToCMYK(color) {
color.space = ColorSpace.cmyk;
var vals = color.colorValue;
for (var j = vals.length - 1; j >= 0; j--) {
vals
= Math.round(vals ); }
color.colorValue = vals;
}
}())
/*
Note that a "Kuler name" is considered to have been
detected if the string "R =" is detected in the swatch
name. It is conceivable that that string could be used
in a non-Kuler name. I consider this a limitation,
not a bug.
*/
— Kas
Copy link to clipboard
Copied
Thanks Kasyan, that’s damn decent of you.
……………………………..
Royston Neale
[Personal info removed by Mod]
Copy link to clipboard
Copied
Hi there. A few years later, but I'd love to run this script and get an error:
Error String: Expected "," but found "{".
I don't know enough to identify the issue here. Any ideas?
Thanks 🙂
Copy link to clipboard
Copied
Not sure you need a script, unless you have a lot of colors that are unnamed. Select all of the swatches in the Swatches Panel, choose Swatch Options, and set the Color Mode to CMYK:
Copy link to clipboard
Copied
Thanks, Rob. I'm hoping to run a script that rounds up or down all cmyk decimal numbers of color (not only swatches) in the document. I'm doing a large color study and not all colors will be made into swatches.
Copy link to clipboard
Copied
I think they must become swatches to run the/any script, or to use your method. This is just how it works. So I can create the swatches to make it work. Thanks again.
Copy link to clipboard
Copied
a script that rounds up or down all cmyk decimal numbers of color (not only swatches) in the document
Try this, note that the conversion numbers depend on your document’s assigned RGB and CMYK profiles:
var c=app.activeDocument.colors;
for (var i = 0; i < c.length; i++){
try {
c[i].space = ColorSpace.CMYK
c[i].colorValue = roundCMYK(c[i].colorValue)
}catch(e) {}
}
/**
* Rounds CMYK values up
* @ param array of CMYK values
* @ return rounded arry
*
*/
function roundCMYK(v){
var va = []
for (var i = 0; i < v.length; i++){
va.push(Math.round(v[i]))
};
return va
}
Copy link to clipboard
Copied
This works! And I don't even need to have the colors included in swatches. THANK YOU 🙂
Copy link to clipboard
Copied
It worked for me too. But I found I had to double click it once to convert to CMYK and then double click it again to round the CMYK values up. I have tweaked the script and this worked for me.
// Convert RGB swatches to CMYK and round the CMYK values
function convertSwatchesRGBtoCMYK() {
var doc = app.activeDocument;
var swatches = doc.colors;
for (var i = 0; i < swatches.length; i++) {
try {
var swatch = swatches[i];
swatch.space = ColorSpace.CMYK;
swatch.colorValue = roundCMYK(swatch.colorValue);
} catch (e) {}
}
alert("RGB swatches converted to CMYK and rounded successfully!");
}
// Rounds CMYK values up
function roundCMYK(v) {
var va = [];
for (var i = 0; i < v.length; i++) {
va.push(Math.round(v[i]));
}
return va;
}
// Run the script to convert RGB to CMYK and round the CMYK values
convertSwatchesRGBtoCMYK();