6 Replies Latest reply on Apr 4, 2017 5:38 AM by tpk1982

    Getting RGB and CMYK values

    tpk1982 Level 4

      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[i];  
          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