Skip to main content
brian_p_dts
Community Expert
Community Expert
April 29, 2021
Answered

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

  • April 29, 2021
  • 4 replies
  • 5151 views

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
}

 

This topic has been closed for replies.
Correct answer CarlosCanto

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?


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

 

4 replies

brian_p_dts
Community Expert
Community Expert
May 5, 2021

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();
Charu Rajput
Community Expert
Community Expert
May 5, 2021

Hi @brian_p_dts 

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

 

 

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
brian_p_dts
Community Expert
Community Expert
May 5, 2021

Thank you, Charu. Exactly what I needed. 

femkeblanco
Legend
April 29, 2021

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.

brian_p_dts
Community Expert
Community Expert
April 29, 2021

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. 

CarlosCanto
Community Expert
Community Expert
April 29, 2021

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

CarlosCanto
Community Expert
Community Expert
April 29, 2021

"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"

brian_p_dts
Community Expert
Community Expert
April 29, 2021

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

Silly-V
Legend
April 29, 2021

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

brian_p_dts
Community Expert
Community Expert
April 29, 2021

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. 

brian_p_dts
Community Expert
Community Expert
April 29, 2021

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


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?