Skip to main content
Royyo
Participant
August 22, 2018
Answered

rgb to cmyk script

  • August 22, 2018
  • 1 reply
  • 4002 views

RGB to CMYK (.0)

I had this very useful script years ago and then lost it.

It was posted on InDesignSecrets.com on November 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.

This topic has been closed for replies.
Correct answer rob day

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. 

 


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
}

 

1 reply

Kasyan Servetsky
Legend
August 22, 2018

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

Royyo
RoyyoAuthor
Participant
August 22, 2018

Thanks Kasyan, that’s damn decent of you.

……………………………..

Royston Neale

[Personal info removed by Mod]

http://roystonc.daportfolio.com