rgb to cmyk script

Community Beginner ,
Aug 22, 2018 Aug 22, 2018

Copy link to clipboard

Copied

RGB to CMYK (.0)

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.

TOPICS
Scripting

Views

1.8K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Guru , Aug 22, 2018 Aug 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() {

 

...

Likes

Translate

Translate
Adobe Community Professional , Jul 15, 2022 Jul 15, 2022

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
...

Likes

Translate

Translate
Guru ,
Aug 22, 2018 Aug 22, 2018

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 22, 2018 Aug 22, 2018

Copy link to clipboard

Copied

Thanks Kasyan, that’s damn decent of you.

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

Royston Neale

[Personal info removed by Mod]

http://roystonc.daportfolio.com

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

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 🙂

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 15, 2022 Jul 15, 2022

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:

 

Screen Shot 10.pngScreen Shot 11.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

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. 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 15, 2022 Jul 15, 2022

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
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

LATEST

This works! And I don't even need to have the colors included in swatches. THANK YOU 🙂

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines