19 Replies Latest reply on Oct 18, 2012 12:10 AM by Trevorׅ

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

    Loic.Aigon Adobe Community Professional



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


      So I wrote :







      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



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


      And indeed if I give :


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


      The UI dialog displays "None".


      Why Pure Yellow is None ?



        • 1. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
          Harbs. Level 6

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



          • 2. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
            Laubender Adobe Community Professional & MVP



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


                $.writeln("IndexNumber: "+n+"       color.name: "+app.colors[n].name);




            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].



            • 3. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
              Loic.Aigon Adobe Community Professional

              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 !



              • 4. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                Harbs. Level 6

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



                • 5. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                  Laubender Adobe Community Professional & MVP



                  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].




                  var d=app.activeDocument;
                  $.writeln("list of app swatches:");
                  $.writeln("\rlist of document swatches:");


                  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.



                  • 6. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                    Harbs. Level 6

                    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){
                        var swatches = docOrApp.swatches.everyItem().getElements();
                        for(var i=0;i<swatches.length;i++){
                            if(swatches[i].hasOwnProperty("colorValue") || swatches[i].hasOwnProperty("gradientStops") ){
                            return swatches[i];
                        return null
                    • 7. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                      Marc Autret Level 5

                      > 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


                      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[i].constructor==Swatch ) ret.push(swatches[i].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[i].constructor==Swatch ) return swatches[i];
                           return null;




                      • 8. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                        Marc Autret Level 5

                        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?




                        • 9. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                          Harbs. Level 6

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



                          • 10. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                            Harbs. Level 6

                            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.



                            • 11. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                              Dave Saunders Level 4

                              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.



                              • 12. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                Marc Autret Level 5

                                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.




                                • 13. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                  Dave Saunders Level 4

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


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



                                  • 14. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                    Laubender Adobe Community Professional & MVP

                                    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.




                                    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…



                                    • 15. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                      Marc Autret Level 5

                                      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...)

                                      • 16. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                        Laubender Adobe Community Professional & MVP

                                        Hi, Marc!



                                        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:



                                        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



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



                                        • 17. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                          Dave Saunders Level 4

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



                                          • 18. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                            Loic.Aigon Adobe Community Professional

                                            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.



                                            • 19. Re: Is that a CS5 bug (app.findObjectPreferences.fillColor)
                                              Trevorׅ Adobe Community Professional

                                              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


                                                   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