8 Replies Latest reply on Feb 1, 2017 11:03 AM by vevarela

    Illustrator CC 2015 Selecting object based on fill CMYK values

    vevarela Level 1

      Hello,

       

      I am trying to write a script for Illustrator 2015 that will change objects with a certain CMYK callout in my document to grayscale. The problem is that the objects appear to have been converted to RGB, while the rest of the document is set to CMYK. Another issue is that I need to make sure that the script does not change the other objects in the document to grayscale. Is there a way to write a script that selects object based on their CMYK values and then executes the convert to grayscale menu item under Edit Color?

       

      After doing some research I found that the code below will execute the menu item needed, but am not sure how to select certain objects with a specific color callout.

       

      app.executeMenuCommand ('Colors7')

       

      Finally, we need the code to automatically select the object as opposed to manually selecting the necessary object before running the script. We have numerous files that we need to convert.

       

      I am new to JavaScript and also with scripting with Illustrator. Any help is appreciated.

        • 1. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
          Silly-V Adobe Community Professional

          What do you mean by "object" and having been converted to RGB?

          Here's a snipped that works in a CMYK document, it works on paths only, and only on their fill colors.

          The UI dialog is most rudimentary because there aren't even any labels: it's just C M Y K from top to bottom.

           

          #target illustrator

          function test(){

               var w = new Window("dialog");

               var input_C = w.add("edittext", undefined, "0");

               input_C.characters = 4;

               var input_M = w.add("edittext", undefined, "0");

               input_M.characters = 4;

               var input_Y = w.add("edittext", undefined, "0");

               var input_K = w.add("edittext", undefined, "0");

               input_Y.characters = 4;

               var btn_ok = w.add("button", undefined, "Ok");

               input_K.characters = 4;

               if(w.show() == 2){

                    return;

               }

               var doc = app.activeDocument;

               var thisPath;

               doc.selection = null;

               for(var i=0; i < doc.pathItems.length; i++){

                    thisPath = doc.pathItems[i];

                    if(thisPath.filled && (Math.round(thisPath.fillColor.cyan) == input_C.text * 1) &&

                         (Math.round(thisPath.fillColor.magenta) == input_M.text * 1) &&

                         (Math.round(thisPath.fillColor.yellow) == input_Y.text * 1) &&

                         (Math.round(thisPath.fillColor.black) == input_K.text * 1)

                    ){

                         thisPath.selected = true;

                    }

               };

               app.executeMenuCommand ('Colors7');

          };

          test();

          2 people found this helpful
          • 2. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
            vevarela Level 1

            Sorry by object I meant outlined text.

            The outlined text in reference has a CMYK value of 0,0,0,100, but the hex value reads as #231F20. This makes me believe that the outlined text had been converted previously to RGB as the outlined text is a four color build upon exporting to a pdf. Also for reference the color mode of the entire document is set to CMYK color.

             

            Thank you for the script! We just tested it and it doesn't appear to work as needed, but it is a great guide to get us started. If you have any other recommendations or tips please let me know .

            1 person found this helpful
            • 3. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
              Silly-V Adobe Community Professional

              So it's text that has been converted to outlines?

              Try this!

               

              #target illustrator

              function test(){

                   var w = new Window("dialog");

                   var input_C = w.add("edittext", undefined, "0");

                   input_C.characters = 4;

                   var input_M = w.add("edittext", undefined, "0");

                   input_M.characters = 4;

                   var input_Y = w.add("edittext", undefined, "0");

                   var input_K = w.add("edittext", undefined, "0");

                   input_Y.characters = 4;

                   var btn_ok = w.add("button", undefined, "Ok");

                   input_K.characters = 4;

                   if(w.show() == 2){

                        return;

                   }

                   var doc = app.activeDocument;

                   var thisPath;

                   doc.selection = null;

                   for(var i=0; i < doc.compoundPathItems.length; i++){

                        thisPath = doc.compoundPathItems[i].pathItems[0];

                        if(thisPath.filled && (Math.round(thisPath.fillColor.cyan) == input_C.text * 1) &&

                             (Math.round(thisPath.fillColor.magenta) == input_M.text * 1) &&

                             (Math.round(thisPath.fillColor.yellow) == input_Y.text * 1) &&

                             (Math.round(thisPath.fillColor.black) == input_K.text * 1)

                        ){

                             thisPath.parent.selected = true;

                        }

                   };

                   app.executeMenuCommand ('Colors7');

              };

              test();

              2 people found this helpful
              • 4. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
                vevarela Level 1

                Hi Silly-V,

                 

                Yes it is outlined text. Thank you for sending that over!  After testing with the new code, unfortunately it still doesn't work. BUT I don't think its the code. I believe the problem has to do with the color values of the outlined text. I was able to replicate the issue in a new document. I have attached a link below to dropbox where my test file is located. If you have time to look at it great! If not, I totally understand as you have already provided useful code that I can work with.

                 

                https://www.dropbox.com/s/r4vg9n3etm83ulz/Test%20File.ai?dl=0

                 

                Thank you for your time

                • 5. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
                  Silly-V Adobe Community Professional

                  I'll take a look at it, sure - right now the dropbox website is not sending the correct security certificate though.

                  • 6. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
                    vevarela Level 1

                    Great! Thank you very much!

                     

                    I had this issue before with Dropbox. For me it had to do with my anti virus software. The link below helped me:

                     

                    Dropbox can't establish a secure connection - Dropbox Help - Dropbox

                     

                    If that doesn't work, I have attached the file to my google drive account.

                     

                    https://drive.google.com/drive/folders/0Bz63tyLsBJXcLVJhdlpScFJuOXM?usp=sharing

                    • 7. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
                      Silly-V Adobe Community Professional

                      Oh yea, the script rounds all the values for the values where there are decimals. Right now it uses the normal rounding rule where 69.53 is 70 and 69.35 is 69. If you don't want to think the process of rounding, we can use Math.floor instead of Math.round so you'd only have to type the 1st whole numbers and just forget about the decimal.

                      To change this, you can edit your script by yourself : just find & replace all Math.round with Math.floor

                      1 person found this helpful
                      • 8. Re: Illustrator CC 2015 Selecting object based on fill CMYK values
                        vevarela Level 1

                        Changing it to Math.floor Worked!

                         

                        Thank you for your help! I appreciate it very much