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

Community Beginner ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

"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]);
}
}
}
}
 
TOPICS
Scripting

Views

551

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 ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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

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
Community Beginner ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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

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 ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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 )

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
Community Beginner ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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.

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 ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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

 

varresultObject = myDoc.findObject();

 

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

 

 

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
Community Beginner ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi Uwe,

I tried to assign a swatch, color or a String (of a Colorname) to

app.findObjectPreferences.fillColor

but it will throw me an error. It seems that the bug that was found a few years ago is still present?

Thanks Stefan

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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 )

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
Community Beginner ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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

 

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
Contributor ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Tested on Windows 10, InDesign 2021 (16.1)

When I try to assign color/swatch objects to the fillColor properties I get the same error as Brian

But when I use the color names it works.

var curDoc = app.activeDocument;

try {
    app.findObjectPreferences = app.changeObjectPreferences = null;
	
    app.findObjectPreferences.fillColor = "REPLACE-FILL";

    app.changeObjectPreferences.fillColor = "PANTONE 360 C";

    curDoc.changeObject();
} catch(e) {
    $.writeln(e); 
}

 

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
Community Beginner ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Does it work also a second time? Pls change "REPLACE-FILL" with a different swatch name and try again. And is it actually doing the change in the document?

Thanks Stefan

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 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

LATEST

Hi crazyPanda,

I thought so as well some days ago. Just tested your code on Stefan's test document with my German InDesign 2021 on Windows 10, but was rewarded with this error message in German:

"Error: Ungültiger Wert für Einrichtung der Eigenschaft "fillColor". Swatch, String or NothingEnum enumerator erwartet, aber "REPLACE-FILL" erhalten."

 

Regards,
Uwe Laubender

( ACP )

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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 )

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Had the wrong document open…

Will come back.

 

Regards,
Uwe Laubender

( ACP )

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

All tests done with InDesign 2020 on Windows 10.

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

 

Test-1-FindChangeFillColor-in-GUI-1.PNG

 

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

Test-1-FindChangeFillColor-in-GUI-2.PNG

 

Regards,
Uwe Laubender

( ACP )

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
Community Beginner ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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/27... 

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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 )

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

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 )

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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 )

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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

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
Community Beginner ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Hi Brian,

thanks. This is what I am going to do. Hopefully this issue will be resolved soon.

Stefan

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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 )

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
Guide ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

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

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

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 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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

 

Regards,
Uwe Laubender

( ACP )

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