app.executeMenuCommand("Find Fill Color menu item") not working?

Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Sorry if this is obvious, I'm more accustomed to ID scripting. I am changing the default fill of an open EPS document in CMYK color profile, and attempting to select path items with that default fill applied. When I run the script, I see the default fill color change in the app, but nothing is selected. If I then go to "Select >> Same >> Fill Color" all of the path items I want are selected. Am I calling the wrong menu command? Any help would be appreciated. 

 

var changeColor = function(doc) {
    doc.selection = null;
    var cmykCol = getColor([73, 0, 99, 0], "aGreen");
    doc.defaultFillColor = cmykCol;
    app.executeMenuCommand("Find Fill Color menu item");
    app.redraw();
    $.writeln(doc.selection.length) //returns 0
}

 

TOPICS
Scripting

Views

617

Likes

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 2 Correct Answers

Adobe Community Professional , Apr 29, 2021 Apr 29, 2021
Hmm, those are RGB colors. This script works: #target illustrator function test(){ var changeColor = function (doc) { var starterColor = doc.selection[0].fillColor; doc.selection = null; doc.defaultFillColor = starterColor; app.executeMenuCommand("Find Fill Color menu item"); } var doc = app.activeDocument; changeColor(doc); }; test(); So maybe the issue is that your CMYK function may be changing the color and making it in a different color mode first, then it can't select ...

Likes

Translate

Translate
Adobe Community Professional , Apr 29, 2021 Apr 29, 2021
I tried your script as is except I didn't use the getColor function, I created a swatch myself. It worked fine, it selected 2 pieces, plus I rectangle I had made with the same color values. to get color values, I selected one of your green pieces and run selection[0].fillColor.cyan

Likes

Translate

Translate
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Try putting the redraw after you do the default fill but before you execute the menu command?

Likes

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
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

No dice, unfortunately. Maybe something funky with this particular file? 😞 Tried on a fresh file and it was fine. 

 

Client was saying they were trying to change some of the colors on the problem file and the colors were reverting back after saving the document. Nothing is immediately jumping out to me on any of the layer items. 

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Any way you can remove any unnecessary info from the file and upload it so we can see?

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Thanks for looking. File attached. Script is making the green CMYK color on the artboards. 

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Hmm, those are RGB colors.

This script works:

#target illustrator
function test(){
	var changeColor = function (doc) {
		var starterColor = doc.selection[0].fillColor;
    doc.selection = null;
    doc.defaultFillColor = starterColor;
    app.executeMenuCommand("Find Fill Color menu item");
	}
	var doc = app.activeDocument;
	changeColor(doc);
};
test();

 

So maybe the issue is that your CMYK function may be changing the color and making it in a different color mode first, then it can't select the same fill color? Try to select them all first and then do the change.

 

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

I get this error on the defaultFillColor line after having selected one of the path items with the green applied: 

Runtime Error: Error Code# 1238: Required value is missing @ file

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

it worked for me but I made my own swatch "aGreen" 

 

the problem is probably decimals, the Green pieces have

73.0525672435761

0

99.1302311420441

0

 

while you're creating a 73, 0, 99, 0 swatch

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

In Silly V's script or my script?

 

I am changing the default fill to the 73,99 cmyk with my code. I see this happen in the document when I run the script if the default fill is a different color. If I code out the app.execute command, and manually Select Same Fill Color, then all the pieces I want get selected. But the app menu command won't execute. I don't see where there are any percentages...can you tell me where you saw that?

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Ummm... got nothing - turn off your GPU preview?

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

I tried your script as is except I didn't use the getColor function, I created a swatch myself. It worked fine, it selected 2 pieces, plus I rectangle I had made with the same color values.

 

to get color values, I selected one of your green pieces and run

selection[0].fillColor.cyan

 

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Thanks, Carlos. I definitely think it's related to trying target hex values in a CMYK document, and the percentages helped me get there. I think the doc needs to be converted to RGB colorspace to let me more correctly pick the right color.

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Definitely something to do with the interplay between RGB and CMYK colors. Thanks for helping me to narrow it down. 

Likes

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
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

"Find Fill Color menu item" is the equivalent to "Select->Same->Fill Color" you have to select an object before running the command. The command will select other objects with the same fill as your selection.

 

to change other items color, you have to select them first, then you can update the default color

 

assuming your items are filled with White, it would be something like this

1. select one item with the color you need to find ("White")

1.1 or create a temporary path and fill it with "White"

2. do "Find Fill Color menu item" (to select other items with the same White fill)

3. change defaultFillColor to "aGreen"

Likes

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
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Find Same Fill works with no selection, and will select all objects with document's currently set default fill. 

Likes

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
Enthusiast ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

The script works for me. Select > Same > Fill Color also works with a selected swatch, as opposed to a selected path (selects paths with the same selected swatch). I cannot see why it won't work. But I wonder what the point of redraw is, since all of this is a selection process with no drawing.

Likes

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
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

It works on other documents I set up, but not this document. Something buggy in these documents. I tried adding redraw as a debugging step; it didn't work without. Thanks for testing. 

Likes

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

oops, you're both correct, it does work without selecting.

Likes

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
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Back again on this thread. Think I've solved the color selection issues; my script is now selecting the right colors. But, it is not changing the colors to new colors in one version of a document. It is correctly changing the fill in another version of the document. If I try to find the chroma object 100 color (the nude), it finds and replaces that color. I can see the script selecting the green in the attached doc, but it is not changing the color. Occasionally, but not always, doc.selection[i].fillColor = repSwatch.color will error as undefined. 

Alerting the cyan of the new fill color shows that it was properly replaced, but it it is still displaying the old color. I can't tell any difference between these two docs. Can anyone help? It's driving me crazy. 

 

var getCMYKSwatch = function(cmykArr, doc, key) {
    var bc = new CMYKColor();
    bc.cyan = cmykArr[0];
    bc.magenta = cmykArr[1];
    bc.yellow = cmykArr[2];
    bc.black = cmykArr[3];
    var swatch = doc.swatches.add();
    swatch.color = bc;
    swatch.name = "rep" + key;
    return swatch;
};

var unitTest = function() {
    var doc = app.activeDocument;
    alert(doc.name);
    var defaultSwatch = getCMYKSwatch(chromakey["0"], doc, "0");
    doc.selection = null;
    doc.defaultFillColor = defaultSwatch.color;
    var repSwatch = getCMYKSwatch(chromakey["55"], doc, "55");
    app.executeMenuCommand("Find Fill Color menu item");
    alert(doc.selection.length);
    for (var i = 0; i < doc.selection.length; i++) {
       app.redraw();
       doc.selection[i].filled = true;
       doc.selection[i].fillColor = repSwatch.color;
       alert(doc.selection[i].fillColor.name);
    }
};

var chromakey = {
    "0": [75, 0, 100, 0],
    "55": [3, 100, 58, 10],
    "100": [10, 27, 35, 6],
};

unitTest();

Likes

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
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Hi @brianp311 

I have noticed few things

 

1. Color is updating in good.eps but not in bad.eps

Reason : In good.eps file when green color objects are selected they all are path items and in bad.eps those path items isinside the group. So when you do 

 

 doc.selection[i].fillColor = repSwatch.color;

 

This will only work for path items not when doc.selection[i] is a group. For better understanding please see screen shot below

Screenshot 2021-05-05 at 1.29.23 PM.png

 

Screenshot 2021-05-05 at 1.29.31 PM.png

 

2. Name is returning undefined

fillColor is either CMYKColor or RGBColor based on the document setup. For you it is CMYK Color. CMYK Color does not have name property, therefore it is returning the undefined. See link below

https://ai-scripting.docsforadobe.dev/jsobjref/CMYKColor/?highlight=CMYK

 

Instead swatch have name property. In your code you are giving name to the swatch

swatch.name = "rep" + key;

 

not CMYKColor bc. There is no statment like bc.name

 

I hope I am able to clarify few things and make you understand.

Best regards

Likes

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
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

Thank you, Charu. Exactly what I needed. 

Likes

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