• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Getting RGB and CMYK values

Guide ,
Apr 03, 2017 Apr 03, 2017

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

TOPICS
Scripting

Views

671

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 1 Correct answer

Guru , Apr 04, 2017 Apr 04, 2017

Should be

    myColor=app.documents[0].swatches;   

and not

    myColor=app.documents[0].colors;   

Please mark as answered,

Thanks

Trevor

Votes

Translate

Translate
Guru ,
Apr 03, 2017 Apr 03, 2017

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

Votes

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
Guide ,
Apr 03, 2017 Apr 03, 2017

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

Votes

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
Guru ,
Apr 04, 2017 Apr 04, 2017

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;}

Votes

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
Guide ,
Apr 04, 2017 Apr 04, 2017

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

Votes

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
Guru ,
Apr 04, 2017 Apr 04, 2017

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

Votes

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
Guide ,
Apr 04, 2017 Apr 04, 2017

Copy link to clipboard

Copied

LATEST

Yes it is working, thanks a lot

Votes

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