16 Replies Latest reply on Dec 13, 2013 4:38 AM by Colin Flashman

    Specific Colour changing Script from RGB to CMYK

    babeanz

      I need to change the RGB values (imported from word) to specific CMYK values in Indesign (its not a straight swop) so I need a script or a similar plug-in that enables me to input the colour values for the CMYK so they automatically change.... the doc i work on is huge and im importing from a word file many times so i need to save time!!

       

      Can anyone help me?

       

      Thank you!

        • 1. Re: Specific Colour changing Script from RGB to CMYK
          csm_phil Level 4

          Hi Babe,

           

          Please try the below JS code.

           

           

          var myIDOc = app.activeDocument;
          var mySwatch = myIDOc.swatches;
          for (var j=4; j<mySwatch.length; j++){
              $.write(mySwatch[j].space);
               if(mySwatch[j].space ==ColorSpace.RGB){
                   if(mySwatch[j].name=="Word_R0_G0_B0"){// Edit this line if you use any spcific color name  otherwise this script will replace the RGB to CMYK.
                       mySwatch[j].model=ColorModel.PROCESS;
                       mySwatch[j].space = ColorSpace.CMYK;
                       //mySwatch[j].name = 'sample';
                       mySwatch[j].colorValue=[0,100,100,0];
                       }
                   }
               }
          

           

           

          thx,

          csm_phil

          • 2. Re: Specific Colour changing Script from RGB to CMYK
            babeanz Level 1

            Hi Phil, thanks so much for this... im a total novice but if my RGB colour was R132 G50, B255 and my CMYK was C48, M72, Y0, K0

            where would these fields need to go?

             

            Sorry to be pain? Can i run it through Extended script toolkit 2?

             

            Thanks

            • 3. Re: Specific Colour changing Script from RGB to CMYK
              babeanz Level 1

              Phil This works! Excellent!! BUt it doesnt change the colour name in the swatch panel? I also need to do this for more colours how would this figure into the code?

              Thanks your a star!!!

              • 4. Re: Specific Colour changing Script from RGB to CMYK
                csm_phil Level 4

                Hi Babe,

                 

                I have modifed the JS code as per your above mentioned RGB values.

                 

                 

                var myIDOc = app.activeDocument;
                var mySwatch = myIDOc.swatches;
                for (var j=4; j<mySwatch.length; j++){
                    try{
                         if(mySwatch[j].space ==ColorSpace.RGB){
                             //plesae you can edit the RGB values as per the InDesign swatches panel name just put into here.
                             //if(mySwatch[j].name=="R132" || mySwatch[j].name=="G50" || mySwatch[j].name=="B255"){//may be this is correct you can check the indesign swatches name
                             if(mySwatch[j].name=="R132 G50 B255"){// may be this is correct you can check the indesign swatches name
                                 mySwatch[j].model=ColorModel.PROCESS;
                                 mySwatch[j].space = ColorSpace.CMYK;
                                 //mySwatch[j].name = 'sample';
                                 mySwatch[j].colorValue=[48,72,0,0];
                                 }
                             }
                         }catch(e){}
                     }
                

                 

                 

                thx,

                csm_phil

                • 5. Re: Specific Colour changing Script from RGB to CMYK
                  babeanz Level 1

                  Hello Phil,

                  Sorry to bother you again but can this code also be adapted to change the swatch name in the swatches panel?

                  so basically after telling the RGB colour to change to its defined CMYK value can the name be changed to its CMYK value and merged with its existing CMYK value so there are no duplicate colours in the pallette?

                   

                  I appreciate you help and this is a great learning curve for me so thanks a million for you time helping me!

                   

                  Babeanz

                  • 6. Re: Specific Colour changing Script from RGB to CMYK
                    csm_phil Level 4

                    Hi Babeanz,

                     

                    Please try the below JS code, I hope you expect this right?

                     

                     

                    var myIDOc = app.activeDocument;
                    var mySwatch = myIDOc.swatches;
                    for (var j=4; j<mySwatch.length; j++){
                        try{
                             if(mySwatch[j].space ==ColorSpace.RGB){
                                 if(mySwatch[j].name=="R132 G50 B255"){// may be this is correct you can check the indesign swatches name
                                     mySwatch[j].model=ColorModel.PROCESS;
                                     mySwatch[j].space = ColorSpace.CMYK;
                                     var myCV = mySwatch[j].colorValue=[48,72,0,0];
                                     mySwatch[j].name = "C=" + myCV[0] + " M=" + myCV[1] +" Y=" + myCV[2] + " K=" + myCV[3];
                    
                                     }
                                 }
                             }catch(e){alert(e)}
                         }
                    

                     

                     

                    thx

                    csm_phil

                    • 7. Re: Specific Colour changing Script from RGB to CMYK
                      babeanz Level 1

                      Hi Phil, Sorry i havnt been back in touch! I cant get this code to work on my doc...

                       

                      var myIDOc = app.activeDocument;

                      var mySwatch = myIDOc.swatches;

                      for (var j=4; j<mySwatch.length; j++){

                          try{

                               if(mySwatch[j].space ==ColorSpace.RGB){

                                   if(mySwatch[j].name=="Word_R122_G75_B153"){// may be this is correct you can check the indesign swatches name

                                       mySwatch[j].model=ColorModel.PROCESS;

                                       mySwatch[j].space = ColorSpace.CMYK;

                                       var myCV = mySwatch[j].colorValue=[100,0,0,0];

                                       mySwatch[j].name = "C=" + myCV[100] + " M=" + myCV[0] +" Y=" + myCV[0] + " K=" + myCV[0];

                       

                                       }

                                   }

                               }catch(e){alert(e)}

                           }

                       

                       

                      the new swatch is called: C=undefined M=100 Y=100 K=100 (the actual colour is 100 C tho!)

                       

                      Can you help? Am i doing something wrong?

                       

                      Thanks in advance!!

                      • 8. Re: Specific Colour changing Script from RGB to CMYK
                        babeanz Level 1

                        Also if i end up with 2 CMYK swatches EG:

                        C100 M100 Y100 K100

                        C100 M100 Y100 K100 2

                         

                        Can they merge automatically?

                         

                        ultimately to keep the swatches panel as clean as poss so there are no duplicate colours!

                         

                        Thanks!!

                        • 10. Re: Specific Colour changing Script from RGB to CMYK
                          csm_phil Level 4

                          Hi Babenz,

                           

                          I have modifed the JS code, Please try and post your feedback. If its work plesae select the answer question.

                           

                           

                          var myIDOc = app.activeDocument;
                          var mySwatch = myIDOc.swatches;
                          for (var j=4; j<mySwatch.length; j++){
                              try{
                                  if(mySwatch[j].space ==ColorSpace.RGB){
                                      mySwatch[j].model=ColorModel.PROCESS;
                                      mySwatch[j].space = ColorSpace.CMYK;
                                      var myCV = mySwatch[j].colorValue;
                                      try{
                                          mySwatch[j].name = "C=" + Math.round(myCV[0]) + " M=" + Math.round(myCV[1]) +" Y=" + Math.round(myCV[2]) + " K=" + Math.round(myCV[3]);
                                          }catch(e){
                                              mySwatch[j].remove();
                                              }
                                          }
                                      }catch(e){alert(e)}
                                  }
                          

                           

                           

                          thx,

                          csm_phil

                          • 11. Re: Specific Colour changing Script from RGB to CMYK
                            babeanz Level 1

                            Hi Phil... Hmmm not sure if i explained myself! Or maybe I am being thick.... I tried the new code but im not sure I was clear on my problem?

                             

                             

                            This is the current code i use to change the RGN values to the CMYK is: I have entered the RGB and CMYK values as they need to be changed and it works but the swatch pallette ends up looking messy! See below.

                             

                            var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R122_G75_B153"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[48,72,0,0];

                                             mySwatch[j].name = "C=" + myCV[48] + " M=" + myCV[72] +" Y=" + myCV[0] + " K=" + myCV[0];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                            var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R255_G0_B255"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[0,100,0,0];

                                             mySwatch[j].name = "C=" + myCV[0] + " M=" + myCV[100] +" Y=" + myCV[0] + " K=" + myCV[0];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                              var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R0_G0_B255"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[100,0,0,0];

                                             mySwatch[j].name = "C=" + myCV[100] + " M=" + myCV[0] +" Y=" + myCV[0] + " K=" + myCV[0];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                              var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R255_G255_B255"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[0,0,0,0];

                                             mySwatch[j].name = "C=" + myCV[0] + " M=" + myCV[0] +" Y=" + myCV[0] + " K=" + myCV[0];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                              var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R0_G0_B0"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[0,0,0,100];

                                             mySwatch[j].name = "C=" + myCV[0] + " M=" + myCV[100] +" Y=" + myCV[0] + " K=" + myCV[100];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                              var myIDOc = app.activeDocument;

                            var mySwatch = myIDOc.swatches;

                            for (var j=4; j<mySwatch.length; j++){

                                try{

                                     if(mySwatch[j].space ==ColorSpace.RGB){

                                         if(mySwatch[j].name=="Word_R234_G229_B255"){// may be this is correct you can check the indesign swatches name

                                             mySwatch[j].model=ColorModel.PROCESS;

                                             mySwatch[j].space = ColorSpace.CMYK;

                                             var myCV = mySwatch[j].colorValue=[8,10,0,0];

                                             mySwatch[j].name = "C=" + myCV[8] + " M=" + myCV[10] +" Y=" + myCV[0] + " K=" + myCV[0];

                             

                                             }

                                         }

                                     }catch(e){alert(e)}

                                 }

                             

                            The outcome is the swatch pallette attached:

                             

                            Screen Shot 2012-10-31 at 09.29.40.png

                             

                            How do I incorporate the new code to make sure all the values are hopefully to end up looking similar to this!!??

                            Screen Shot 2012-10-31 at 09.31.30.png

                             

                            Thanks for all your time and effort helping me!

                             

                            babeanz

                            • 12. Re: Specific Colour changing Script from RGB to CMYK
                              csm_phil Level 4

                              Hi Babe,

                               

                              Have you tried the below JS code.

                               

                               

                              var myIDOc = app.activeDocument;
                              var mySwatch = myIDOc.swatches;
                              for (var j=4; j<mySwatch.length; j++){
                                  try{
                                      if(mySwatch[j].space ==ColorSpace.RGB){
                                          mySwatch[j].model=ColorModel.PROCESS;
                                          mySwatch[j].space = ColorSpace.CMYK;
                                          var myCV = mySwatch[j].colorValue;
                                          try{
                                              mySwatch[j].name = "C=" + Math.round(myCV[0]) + " M=" + Math.round(myCV[1]) +" Y=" + Math.round(myCV[2]) + " K=" + Math.round(myCV[3]);
                                              }catch(e){
                                                  mySwatch[j].remove();
                                                  }
                                              }
                                          }catch(e){alert(e)}
                                      }
                              

                               

                               

                              If you face the problem still. Please send the InDesign document I will check and let you know.

                               

                              thx,

                              csm_phil

                              • 13. Re: Specific Colour changing Script from RGB to CMYK
                                babeanz Level 1

                                It shows an error say colour name is already used. Will a file accross, whats your email?

                                • 14. Re: Specific Colour changing Script from RGB to CMYK
                                  babeanz Level 1

                                  would like to send you a copy of this file - see screen grabScreen Shot 2012-11-05 at 10.37.02.png

                                  • 15. Re: Specific Colour changing Script from RGB to CMYK
                                    babeanz Level 1

                                    Hi Phil, can I email you a file?

                                    • 16. Re: Specific Colour changing Script from RGB to CMYK
                                      Colin Flashman Adobe Community Professional

                                      Sorry to resurrect an old thread, but I discovered this script and found it quite useful.

                                       

                                      I did make one modification to it: it finds any colour type (in the PROCESS dropdown of the colour menu) followed by RGB, or LAB, in the colour mode dropdown menu and converts only those RGB colours to CMYK:

                                       

                                      replace the line:

                                       

                                       

                                      
                                      if(mySwatch[j].space ==ColorSpace.RGB){
                                      
                                      
                                      

                                       

                                      with the following line:

                                       

                                       

                                      
                                      if(mySwatch[j].space ==ColorSpace.RGB || mySwatch[j].space ==ColorSpace.LAB && mySwatch[j].model===ColorModel.PROCESS){
                                      
                                      
                                      

                                       

                                      I would also add this line to catch any unnamed colours not already in the swatches palette:

                                       

                                       

                                      app.menuActions.item("$ID/Add All Unnamed Colors").invoke();
                                      

                                       

                                      I would add this above the line:

                                       

                                       

                                      var mySwatch = myDoc.swatches;
                                      

                                       

                                      This can then be further complemented by a script released by AJAR productions that sorts swatches alphabetically:

                                       

                                      http://ajarproductions.com/blog/2013/12/13/sort-swatches-in-adobe-indesign/

                                       

                                      Many thanks,

                                       

                                      Colly

                                       

                                      Message was edited by: cdflash Have just noticed this script works on swatches with solid panels, but not with gradients.