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

Illustrator CC 2015 Selecting object based on fill CMYK values

Guest
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.2K

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

Valorous Hero , Jan 31, 2017 Jan 31, 2017

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

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

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;

          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();

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
Guest
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

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 .

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
Valorous Hero ,
Jan 30, 2017 Jan 30, 2017

Copy link to clipboard

Copied

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.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();

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
Guest
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

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

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
Valorous Hero ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

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

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
Guest
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

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

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
Valorous Hero ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

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

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
Guest
Feb 01, 2017 Feb 01, 2017

Copy link to clipboard

Copied

LATEST

Changing it to Math.floor Worked!

Thank you for your help! I appreciate it very much

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