Skip to main content
Balaji Murugesan
Known Participant
June 25, 2020
Question

Am facing this error, try to find object fill color.

  • June 25, 2020
  • 9 replies
  • 3411 views

"Error: Invalid value for set property 'fillColor'. Expected Swatch, String or NothingEnum enumerator, but received in indesign"

 

 

Am facing this error, try to find object fill color.
varmyColors = myDoc.colors;
var_counter = 0;
for(varl=0;l<myColors.length;l++){
if(myColors[l].name.search("DO NOT PRINT","i") >-1 || myColors[l].name.search("DO_NOT_PRINT","i") >-1 || myColors[l].name.search("DONOTPRINT","i") >-1 ){
_counter++;
if (_counter == 1) {
_DO_NOT_PRINT_Swatches.push(myColors[l].name);
_DO_NOT_PRINT_Swatches1.push(myColors[l].name);
}
else{
_DO_NOT_PRINT_Swatches.push("\t\t\t" +myColors[l].name);
_DO_NOT_PRINT_Swatches1.push(myColors[l].name);
}
}
}
for(vars=0;s<_DO_NOT_PRINT_Swatches1.length;s++){
app.findChangeObjectOptions.objectType = ObjectTypes.ALL_FRAMES_TYPE;
app.findObjectPreferences.fillColor = _DO_NOT_PRINT_Swatches1[s];
varresultObject = myDoc.findObject();
if(resultObject.length>0){
var_counter = 0;
for(varobj=0;obj<resultObject.length;obj++){
_counter++;
if(_counter == 1){
_Do_Not_Print_Object_Array.push("page "+resultObject[obj].parentPage.name+"-->"+_DO_NOT_PRINT_Swatches1[s]);
}
else{
_Do_Not_Print_Object_Array.push("\t\t\tpage "+resultObject[obj].parentPage.name+"-->"+_DO_NOT_PRINT_Swatches1[s]);
}
}
}
}
 
This topic has been closed for replies.

9 replies

m1b
Community Expert
Community Expert
March 10, 2023

Hi all, I'm still seeing this bug in ID 18.2. I couldn't find the bug in uservoice, so I created one.

Please vote for it here.

- Mark

Community Expert
April 13, 2021

Note: I unmarked one of my posts above as the Correct Answer.

 

Regards,
Uwe Laubender

( ACP )

Community Expert
April 13, 2021

Hi Brian,

yes of course.

 

What also will work is to build a findChangeQuery XML file, load the query with app.loadFindChangeQuery() and run doc.changeObject().

 

Here just an example of a findChangeQuery XML file contents:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Query>
<Header>
<Version major="5" minor="1">
</Version>
<Application value="Adobe InDesign">
</Application>
<QueryType value="Object" qid="3">
</QueryType>
</Header>
<Description>
<ObjectType value="0">
</ObjectType>
<FindChangeOptions>
<IncludeLockedLayers value="0">
</IncludeLockedLayers>
<IncludeLockedStories value="0">
</IncludeLockedStories>
<IncludeMasterPages value="0">
</IncludeMasterPages>
<IncludeHiddenLayers value="0">
</IncludeHiddenLayers>
<IncludeFootnotes value="1">
</IncludeFootnotes>
</FindChangeOptions>
<FindFormatSettings>
<GraphicsAttribute cls_id="28264" value="REPLACE-FILL">
</GraphicsAttribute>
</FindFormatSettings>
<ReplaceFormatSettings>
<GraphicsAttribute cls_id="28264" value="PANTONE 360 C">
</GraphicsAttribute>
</ReplaceFormatSettings>
</Description>
</Query>

 

If that XML file is saved to the right folder, in my case with my German InDesign 2020 on Windows 10, this is:

Username > AppData > Roaming > Adobe > InDesign > Version 15.0 > de_DE > Find-Change Queries > Object

 

Then the following code will work if we assume that the file's name is

ReplaceFillColor.xml

 

app.loadFindChangeQuery( "ReplaceFillColor", SearchModes.OBJECT_SEARCH );
app.documents[0].changeObject();

 

Of course we have to do research on the various cls_id values and other things as well.

 

Regards,
Uwe Laubender

( ACP )

Legend
April 14, 2021

In the C++ SDK, attributes are objects with a "boss class" identified by a class ID.

28264 would be kGraphicStyleFillRenderingAttrBoss (kGraphicStylesPrefix 0x6e00 + offset 104)

Community Expert
April 12, 2021

Ok. We first first have to add a color named "REPLACE-FILL" to the application. Not the document.

Then we could define that as fill color like that:

app.findObjectPreferences.fillColor = "REPLACE-FILL";

 Did not test anything else. Just to give you a hint for the next step.

 

Regards,
Uwe Laubender

( ACP )

Community Expert
April 13, 2021

No. That does not work. I could swear adding the color to the application worked for me at least once.

But unfortunately only once. Tried to repeat it today and had the same error messages as before.

 

Sorry,
Uwe Laubender

( ACP )

brian_p_dts
Community Expert
Community Expert
April 13, 2021

Definitely getting the same bug. Seems to be an issue with Find/Change Object. The following could be a viable workaround: 

var curDoc = app.activeDocument;
var apis = curDoc.allPageItems;
var fillCol = curDoc.swatches.itemByName("REPLACE-FILL");
var panCol = curDoc.swatches.itemByName("PANTONE 360 C");
for (var i = 0; i < apis.length; i++) {
    try {
        if (apis[i].fillColor == fillCol) {
            apis[i].fillColor = panCol;
        }
    } catch(e) {
        $.writeln(e);
    }
}
Community Expert
April 12, 2021

All tests done with InDesign 2020 on Windows 10.

Did some parameters in Object Find/Change in the GUI like that:

 

 

In that situation I would expect that the script:

 

app.findObjectPreferences.fillColor

 

will return something reasonable. But this is not the case. An error was returned.

Error number is 30615, error message from my German InDesign is "Diese Eigenschaft ist im aktuellen Status nicht zutreffend." ( $ID/kScriptErrNotApplicable )

 

Will test this in other versions of InDesign. This functionality seems to be broken for ExtendScript. In the GUI everything is working as expected if I hit button "Change All":

 

Regards,
Uwe Laubender

( ACP )

Known Participant
April 12, 2021

Hi Uwe,

thanks for your help. I have been studying this Link.

I was referring to this earlier:

https://community.adobe.com/t5/indesign/is-that-a-cs5-bug-app-findobjectpreferences-fillcolor/m-p/2738950 

Community Expert
April 12, 2021

Hah! Me about 10 years ago. Also studying my own answers and findings from that thread…

( Funny. )

 

Thank you for digging!

 

Regards,
Uwe Laubender

( ACP )

Community Expert
April 12, 2021

Hi Stefan,

opened your sample InDesign document with InDesign 2020 on Windows 10.

I cannot see a swatch named "REPLACE FILL", nore can I see a swatch named "PANTONE 360 C".

So your code cannot work with this document.

 

Had the wrong document open…

Will come back.

 

Regards,
Uwe Laubender

( ACP )

Community Expert
April 12, 2021

Had the wrong document open…

Will come back.

 

Regards,
Uwe Laubender

( ACP )

Community Expert
April 12, 2021

Hi Stefan,

don't think we discussed a bug here.

It's only that the name of the color was not sufficient and a color object was expected.

 

Your case seems to be a little different.

Can you provide minimal code with the color name and a document where the color is defined in the Swatches panel?

 

Thanks,
Uwe Laubender

( ACP )

Known Participant
April 12, 2021

None of these replacements work for me (InDesign 2020 15.0.2)

var curDoc = app.activeDocument;
try {
    
    app.findObjectPreferences = app.changeObjectPreferences = null;
    app.findObjectPreferences.fillColor = "REPLACE-FILL"; //"Registration"; 
    //app.changeObjectPreferences.fillColor = "PANTONE 360 C";
    //app.changeObjectPreferences.fillColor = curDoc.swatches.itemByName("PANTONE 360 C");
    app.changeObjectPreferences.fillColor = curDoc.colors.itemByName("PANTONE 360 C");
    curDoc.changeObject();


} catch(e) {
    $.writeln(e);
    
}
brian_p_dts
Community Expert
Community Expert
April 12, 2021

Interesting, here is the error message I'm throwing on Big Sur, 11.2.3, ID 16.0.1

"Error: Invalid value for set property 'fillColor'. Expected Swatch, String or NothingEnum enumerator, but received Color."

Both swatches return as isValid = true. Scratching my head a bit. 

var curDoc = app.activeDocument;
var fillCol = curDoc.swatches.itemByName("REPLACE-FILL");
var panCol = curDoc.swatches.itemByName("PANTONE 360 C");
try {
    app.findObjectPreferences = app.changeObjectPreferences = null;
    app.findObjectPreferences.fillColor = fillCol; //"Registration"; 
    app.changeObjectPreferences.fillColor = panCol;
    curDoc.changeObject();
} catch(e) {
    $.writeln(e); 
}

 

Community Expert
June 25, 2020

Hi,

as far as I can see from your code, this line:

 

app.findObjectPreferences.fillColor = _DO_NOT_PRINT_Swatches1[s];

 

tries to assign the name of a color to the fillColor property.

Instead try the following by assigning the color itself and not its name:

 

 

app.findObjectPreferences.fillColor = 
myDoc.colors.itemByName( _DO_NOT_PRINT_Swatches1[s] );

 

 

I hope, that your myDoc variable refers to the active document.

 

Regards,
Uwe Laubender

( ACP )

 

FWIW: I unmarked this post as the Correct Answer.

Could be that I have to do more tests on the issue.

For alternative solutions see below in this thread.

 

Regards,
Uwe Laubender

( ACP )

Balaji Murugesan
Known Participant
June 25, 2020

I tried this too, but still facing error, but instead of am found one thing,

 

Once try to manual, then the automation working well, but once app quit its shown same.

brian_p_dts
Community Expert
Community Expert
June 25, 2020

The error may be from the line below the .fillColor line:

 

varresultObject = myDoc.findObject();

 

You need a space after 'var' at the start. 

 

 

Community Expert
June 25, 2020

Ir seems you are finding some specific swatch, saving its name and the using it to find some objects. I think the error is on line 

app.findObjectPreferences.fillColor = _DO_NOT_PRINT_Swatches1[s];
Debug and see if this has a valid value when the code reached this point. Maybe the index is wrong.
 
-Manan
-Manan
Balaji Murugesan
Known Participant
June 25, 2020

Yes. it valid value. here index is swatches name.