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

Is that a CS5 bug (app.findObjectPreferences.fillColor)

People's Champ ,
Jun 18, 2010 Jun 18, 2010

Copy link to clipboard

Copied

Hi,

I wanted to go and make a findObject request through scripting. My intention is to find objects with "None" fill color.

So I wrote :

with(app.findObjectPreferences){

fillColor="None";

}

app.findObject() and that returns 0 occurences.

As I have "None" filled objects, I didn't understand why Indesign didn't find them and looked into the find object dialog box to see what is going on.

It appears that the specified color is not None but non specific color.

So I picked "None" in the UI and just request the name of that color via scripting

alert(app.findObjectPreferences.fillColor.name);

Obviously, it should return me "None" but it gave me "C=0 M=0 Y=100 K=0"...

And indeed if I give :

with(app.findObjectPreferences){

fillColor="C=0 M=0 Y=100 K=0";

}

The UI dialog displays "None".

Why Pure Yellow is None ?

Loic

TOPICS
Scripting

Views

5.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
LEGEND ,
Jun 18, 2010 Jun 18, 2010

Copy link to clipboard

Copied

try: app.findObjectPreferences.fillColor = doc.colors.item(0);

Harbs

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
Community Expert ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

@Harbs:

I ran the following test to get a list of the default colors and their names.

for(n=0;n<app.colors.length;n++){
    $.writeln("IndexNumber: "+n+"       color.name: "+app.colors.name);
    };

Result:

IndexNumber: 0       color.name: Black
IndexNumber: 1       color.name: C=0 M=0 Y=100 K=0
IndexNumber: 2       color.name: C=0 M=100 Y=0 K=0
IndexNumber: 3       color.name: C=100 M=0 Y=0 K=0
IndexNumber: 4       color.name: C=100 M=90 Y=10 K=0
IndexNumber: 5       color.name: C=15 M=100 Y=100 K=0
IndexNumber: 6       color.name: C=75 M=5 Y=100 K=0
IndexNumber: 7       color.name: Cyan
IndexNumber: 8       color.name: Magenta
IndexNumber: 9       color.name: Paper
IndexNumber: 10       color.name: Registration
IndexNumber: 11       color.name: Yellow
IndexNumber: 12       color.name:
IndexNumber: 13       color.name:

So doc.colors.item(0) should get "Black", but the script threw an error. I tried doc.color.item(0).name and that gave me fill color "Unknown color".
Next I tested the following line:

app.findObjectPreferences.fillColor = app.activeDocument.colors[1].name;

That finally gave me the desired fill color "None".
Very strange to get a read out of C=0 M=0 Y=100 K=0 when asking for colors[1].name.
I tested other index values. One should asume that setting fillColor to colors[9].name would yield a fill color [Paper]. But not so. I got "Unknown color". Instead colors[5].name did the trick.

If we take a closer look at the list above colors[12] and [13]  seem to have a empty name like that: ""

"Reasonable" index numbers to use were:
[1] => fillColor [None]
[5] => fillColor [Paper]
[6] => fillColor [Registration]
[11] => fillColor [Black]

What's going on here?

Tested with InDesign CS5 German version 7.0.1.

Tried the same with InDesign CS4 6.0.5 but got only one "hit" at all. Got "Unknown color" also on index 1,5,6. With index 11 I was successful to get fillColor [Black].

Uwe

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
LEGEND ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

This is really weird, but either way, the correct way to get a reference to the "None" color is to use the swatches collection.

The same goes for the rest of the saved colors.

doc.swatches[0] is always "None".

Harbs

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
Community Expert ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

@Harbs:

Now I did further testing. Scenario is now that I stripped all unused swatches from active document and shifted the swatch "[None]" from top to the bottom of the color palette. There are four color swatches remaining (from top to bottom): [Registration], [Paper], [Black] and [None].

Script:

var d=app.activeDocument;

$.writeln("list of app swatches:");
for(n=0;n<app.swatches.length;n++){
    $.writeln(app.swatches+"\t"+n+"\t"+app.swatches.name+"\t"+app.swatches.id);
    };

$.writeln("\rlist of document swatches:");
for(n=0;n<d.swatches.length;n++){
    $.writeln(d.swatches+"\t"+n+"\t"+d.swatches.name+"\t"+d.swatches.id);
    };

Result:list of app swatches:
[object Swatch]    0    None    3
[object Color]    1    Registration    4
[object Color]    2    Paper    5
[object Color]    3    Black    6
[object Color]    4    C=100 M=0 Y=0 K=0    10
[object Color]    5    C=0 M=100 Y=0 K=0    11
[object Color]    6    C=0 M=0 Y=100 K=0    12
[object Color]    7    C=15 M=100 Y=100 K=0    13
[object Color]    8    C=75 M=5 Y=100 K=0    14
[object Color]    9    C=100 M=90 Y=10 K=0    15

list of document swatches:
[object Color]    0    Registration    16
[object Color]    1    Paper    15
[object Color]    2    Black    11
[object Swatch]    3    None    14

So it seems that both index- and id-numbers are changing. Furher I am surprised that I get back [object Color] when I asking for app.swatches or activeDocument.swatches with the exception of my swatch named "None" where it gave me [object Swatch].

What if I try to address fillColor with swatches.itemByName()?
With an rectangle object in my active document selected I can change it's fill color to "None" by:

app.selection[0].fillColor = app.activeDocument.swatches.itemByName("None");

However if I'm trying to change findObjectPreferences.fillColor the same way:

app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName("None");

I get an error message (here I have to translate from my German ESTK):
"Incorrect value for property "fillColor", Swatch, String or NothingEnum enumerator expected, but recieved Swatch"

InDesign CS5 7.0.1 German version.

Uwe

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
LEGEND ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

I finally took a few minutes to look at this...

I think the problem stems from the fact that [None] is not a Color at all. It's a Swatch.

In fact I think it's the only true Swatch that truly exists. If you run getElements() on all your swatches, they will either resolve to a Color or Gradient -- all that is except for [None]. Even getElements() returns Swatch on [None].

app.findPreferences.fillColor should accept the [None] swatch as a valid value...

FWIW, Here's a function which wil return [None] no matter where it is...

function getNoColor(docOrApp){
    if(!docOrApp)docOrApp=app;
    var swatches = docOrApp.swatches.everyItem().getElements();
    for(var i=0;i<swatches.length;i++){
        if(swatches.hasOwnProperty("colorValue") || swatches.hasOwnProperty("gradientStops") ){
            continue;
        }
        return swatches;
    }
    return null
}

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
Guide ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

> I think the problem stems from the fact that [None] is not a Color at  all. It's a Swatch.

> In fact I think it's the only true Swatch that truly  exists...

You're absolutely right. It's an important fact to know when you script colors. The Swatch class works mostly like PageItem. It provides an abstract way to index Colors, Gradients, Tints... together -- like PageItem with Rectangle, Oval, TextFrame, etc.

So to get the actual object behind a Swatch, you need to use myObject = mySwatch.getElements()[0].

Then you have:

mySwatch.constructor == Swatch

but:

myObject.constructor == Color (or Tint, or Gradient...)

The only difference is that appOrDoc.swatches.itemByName("None") is really a Swatch (and the only one):

var none1 = app.swatches.itemByName("None");
var none2 = none1.getElements()[0];
alert( none1 === none2 ); // true

The Swatch class has exactly one instance which is labelled None:

function displaySwatchActualInstance(docOrApp)
     {
     if( !docOrApp ) docOrApp=app;
     var ret = [];

        var swatches = docOrApp.swatches.everyItem().getElements();

     for( var i=0 ; i<swatches.length ; ++i )
          if( swatches.constructor==Swatch ) ret.push(swatches.name);
     alert( ret ); // just "None"
     }

I think that appOrDoc.swatches.itemByName("None") always works (?).

If that's not the case, just check the constructor property on the actual objects:

function getNone(docOrApp)
     {
     if( !docOrApp ) docOrApp=app;
     var swatches = docOrApp.swatches.everyItem().getElements();

     for( var i=0 ; i<swatches.length ; ++i )
          if( swatches.constructor==Swatch ) return swatches;

     return null;
     }

@+

Marc

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
LEGEND ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Good point about checking the constructor.

I wonder if some localized versions will fail with itemByName() I always try to steer clear of that way of doing things...

Harbs

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
People's Champ ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi Harbs and sorry for the delay.

Thanks a lot foir your help. However, I thought that using the 0 index would do the trick.

But, as the user is able to drag the swatch from up to bottom, we can't trust the index either.

That's annoying.

Thanks anyway !

Loic

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
Guide ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Anyway this *does not* answer to Loic's original question.

app.findObjectPreferences.fillColor seems to have a serious bug (in CS4 and CS5). Apparently we cannot set this property to the actual None swatch by scripting... Does anybody have a workaround?

@+

Marc

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
LEGEND ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

I don't know about workarounds, but at least I've called this to the attention of some folks at Adobe...

Probably the best you're going to be able to do will be using a loop to examine the fillColor yourself. I don't recall ever scripting find/change of objects (using findObject() or changeObject() ). I've never felt the need to. Looping through all the objects in a document and examining them yourself is generally pretty quick.

Harbs

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
Advocate ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

This works: [Oops -- see following two messages for the truth]

doc = app.documents[0]; app.findObjectPreferences.fillColor = NothingEnum.nothing; myFinds = doc.findObject();

I wonder if CS4 has the same problem?

Yes it does. But the above code works in it, too.

Dave

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
Guide ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi Dave,

Are you sure that using NothingEnum.nothing actually works? I think your code will purely unset the fillColor property, so the findObject() method will probably disregard fillColor and return any object whatever its color... But Loic's script needs to match [None] only.

@+

Marc

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
Advocate ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Ah, you're right Marc.

Sorry folks, that code doesn't work (except in the case where all objects have no fill, which was the case when I "tested" the code.

The problem appears to be that the property is set to accept application-level swatches, which is useless because they're not in use in the document. So, this:

app.findObjectPreferences.fillColor = app.swatches[0];

"works" in the narrow sense that it executes but it does you no good because the following find command doesn't find the page items with the corresponding document swatch.

Interesting. This also "works" in the same way:

app.findObjectPreferences.fillColor = "None";

The swatch it picks up belongs to the application, as this demonstrates:

app.findObjectPreferences.fillColor = "None"; $.writeln(app.findObjectPreferences.fillColor.parent);

So, it looks like the only way to go is find them all and filter out the ones you want (or don't want, depending on how you interpret the word "filter").

Dave

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
Community Expert ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi, Marc!

I think we are missing something important here. Via UI one can only assign a color to the fill or the stroke, IF the color we search for is already applied to an object EXCEPT for the four basic swatches which are always available ([None], [Black], [Paper] and [Registration]). So if you like to search for a defined swatch named "C=100 M=0 Y=50 K=0" which is not assigned to an object, you simply cannot do so.

I checked the constructor of app.findObjectPreferences.fillColor when various colors are assigned from the UI.

app.findObjectPreferences.fillColor.constructor;

gave me the following results:
if fillColor is set in the UI to [None], [Paper], [Black] or [Registration]
Result: Color()

if fillColor is set to nothing at all:
Result: Enumerator()

In that case "app.findObjectPreferences.fillColor;" returns the word NOTHING to the ESTK console.

if a swatch other than [None], [Paper], [Black] or [Registration] is set:
Result: this property is not valid in actual state (rough translation of my German ESTK error message)

I checked the properties with "app.findObjectPreferences.toSource();" (no fill color is asigned in the UI), the property fillColor is found: fillColor:({}).
A fill color out of the basic four swatches reveals the following property: fillColor:resolve("/color[@id=14]"). In the case of this example [Registration] was asigned via UI.
However if a swatch already used in the document like "C=100 M=0 Y=50 K=0" was assigned, the property "fillColor" is not available anymore when checking with toSource(). The property simply has vanished…

Uwe

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
Guide ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi Laubender,

Yes, but the error message you got -- "This property is not available in the current state" or something -- also occurs in ID CS4 when the the fillColor of findObjectPreferences is set to [None] through the UI. ID CS5 has a different display behavior, but the two versions share the bug.

I think Dave is on the good track: app.findObjectPreferences.fillColor expects an Application-level swatch and findObject() fails to resolve it when you call the method from a Document. The bug is surely here. (I don't know how a Document object inherits from the predefined Application swatches: maybe the swatch/color object are actually cloned, maybe they are resolved by reference...)

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
Community Expert ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

Hi, Marc!

What

is working, at least for me in my German version of InDesign CS5 7.0.1, is the following:

app.findObjectPreferences.fillColor = app.colors[1].name;

I don't know why but it sets the fill color of the find Object preferences to [None].

There might be occasions where that does not work. It seems to depend on the app fill colors available if no document is open.

Here a table of my findings if all the pre installed colors of the app are in default order:

app.findObjectPreferences.fillColor = app.colors[1].name     =>[None]     =>ESTK-Result: C=0 M=0 Y=100 K=0
app.findObjectPreferences.fillColor = app.colors[5].name     =>[Paper]     =>ESTK-Result: C=15 M=100 Y=100 K=0

app.findObjectPreferences.fillColor = app.colors[6].name     =>[Registration]     =>ESTK-Result: C=75 M=5 Y=100 K=0

app.findObjectPreferences.fillColor = app.colors[11].name     =>[Black]     =>ESTK-Result: Yellow

See screen shots when no documents are open:

DefaultColorPalette_InDesignCS5_7.0.1.png

If I reduce the available colors to the basic four, only [Black] will work in that way but with a different index number:

app.findObjectPreferences.fillColor = app.colors[5].name     =>[Black]     =>ESTK-Result: Yellow

DefaultColorPalette_MinimumConfig.png

I really hope that Dave is on the right track, but I fear the bug will stop him…

Uwe

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
Advocate ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Just to be clear, I was demonstrating what the bug is, not attempting to work around it.

Dave

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
People's Champ ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Hi guys,

Thanks a lot for your time and interest in that topic. Generally, I am careful to not yell at bugs for no reason. But in this case, I couldn't explain myself the script behaviour.


At least, I know why now.

Loic

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
Guru ,
Oct 18, 2012 Oct 18, 2012

Copy link to clipboard

Copied

Hi All,

The topic here is changing fillColor "None" to another collor

BUT can anyone manage to change ANY color to another color?

Whatever method I use like Uwe's app.findObjectPreferences.fillColor = app.colors[5].name

When I look at the UI it says

Fill:

     Colour: (Unnamed Colour)

When I click on the Specify attributes to find Indesign crashes

BUG OR WHAT!

With out running a script and just useing the UI no problems

ScreenShot069.png   

Regards

Trevor

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

Copy link to clipboard

Copied

FWIW: After all these years the situation has not changed.

 

A possible solution for working with findObjectPreferences.fillColor, changeObjectPreferences.fillColor is to build a findChangeQuery XML file, load it and do changeObject() on a document or on page items. Here some sample code where the file ReplaceFillColor.xml exists in the appropriate folder inside InDesign's preferences:

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

 

More on this in a similar discussion we had in 2020 and where some posts were added recently:

 

Am facing this error, try to find object fill color.
Balaji Murugesan, Jun 25, 2020

https://community.adobe.com/t5/indesign/am-facing-this-error-try-to-find-object-fill-color/td-p/1123...

 

Regards,
Uwe Laubender

( ACP )

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
Community Expert ,
Mar 10, 2023 Mar 10, 2023

Copy link to clipboard

Copied

LATEST

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

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