7 Replies Latest reply on Mar 15, 2017 8:26 AM by Laubender

    Color applied object change color

    maild85880250

      I wrote this code

      But I am getting the error Why?

       

      var findC = [

      "C=100 M=0 Y=0 K=0",

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

      ]

       

      changeC = [

      "C=15 M=100 Y=100 K=0",

      "C=75 M=5 Y=100 K=0"

      ]

       

      var doc = app.activeDocument; 

      app.findObjectPreferences = app.changeObjectPreferences = null; 

       

      for(var i = 0; i < findC.length; ++i) {

        

        

      app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC[i]);

      app.changeObjectPreferences.fillColor =app.activeDocument.swatches.itemByName(changeC[i]);

      app.changeObject(); 

            }

      app.findObjectPreferences = app.changeObjectPreferences = null; 

        • 1. Re: Color applied object change color
          Laubender Adobe Community Professional & MVP

          Hi,

          would you like to tell what "the" error is?
          And what line is throwing this?

           

          Thanks,

          Uwe

          • 2. Re: Color applied object change color
            Laubender Adobe Community Professional & MVP

            Hm.

            Your code is missing at least one comma and at semicolon.

             

            FWIW: I think, findObjectPreferences is broken with InDesign scripting.

            There is at least one fundamental bug.

             

            If I apply a color like "C=100 M=0 Y=0 K=0" to the fill property in the UI,

            app.findObjectPreferences.fillColor returns an error.

             

            The equivalent of: $ID/kScriptErrNotApplicable

            In my German InDesign: "Diese Eigenschaft ist im aktuellen Status nicht zutreffend."


            Tested with CS6 8.1.0 on OSX 10.6.8.

             

            What is your exact version of InDesign and OS ?

             

            Regards,
            Uwe

            • 3. Re: Color applied object change color
              maild85880250 Level 1

              I use ─░ndesing CS6 and in windows10

               

              This error:

              Invalid value for cluster property "fillColor". Expected Swatch, String or NothingEnum enumerator but received Color

               

              Line text:

              app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC[i]);

              • 4. Re: Color applied object change color
                Laubender Adobe Community Professional & MVP

                Seems to be a bug with InDesign's scripting engine.

                You have to search without using findObject .

                 

                Get all the pageItems of the document and evaluate them one after another.

                Perhaps you could use the document.allPageItems array. Beware that this array would not include page items in non-active states of MultiStateObjects (MSOs).


                Write the results to an array or change the fillColor while looping.

                Beware of pageItems where fillColor perhaps throw an exception.

                Like the ones anchored in overset text.

                 

                Regards,
                Uwe

                • 5. Re: Color applied object change color
                  maild85880250 Level 1

                  This my code its run but

                   

                  rectangle don't

                   

                   

                  var myDoc = app.activeDocument;

                  var pi = myDoc.allPageItems;

                  for(j = 0; j < pi.length; ++j) {

                  it = pi[j];

                  if(it && it instanceof TextFrame){      //   &&   rectangle ??

                  for(var k=0; k<findC.length; k++)  {

                  if(it.fillColor.name == findC[k]){

                  it.fillColor = changeC[k];

                  }

                  }

                  }

                  }

                  • 6. Re: Color applied object change color
                    Stefan Rakete Level 2

                    This works for me also on rectangles:

                     

                    var findC = [ "C=100 M=0 Y=0 K=0", "C=0 M=0 Y=100 K=0"];

                    var changeC = [ "C=15 M=100 Y=100 K=0", "C=75 M=5 Y=100 K=0"];

                     

                    var doc = app.activeDocument; 

                    var pi = doc.allPageItems;

                     

                    for (var j = 0; j < pi.length; ++j) {

                     

                        var it = pi[j];

                     

                        if (it.isValid && it instanceof Rectangle) {      //   &&   rectangle ??

                     

                                    for(var k=0; k<findC.length; k++)  {

                     

                                        var curFindColor = findC[k];

                                        var curChangeColor = changeC[k];

                     

                                        if (it.fillColor.name == curFindColor) {

                     

                                            it.fillColor = curChangeColor;

                     

                                        }

                     

                                }

                     

                            }

                     

                    }

                    • 7. Re: Color applied object change color
                      Laubender Adobe Community Professional & MVP

                      Hi together,

                      the first thing I would do is to resolve the individual pageItem:

                       

                      var it = pi[j].getElements()[0];
                      

                       

                      FWIW: Items where fillColor throws an error are images in RGB or CMYK color model.

                      Also other type of graphics. So prepare for them. Or use a try/catch wrapper.

                       

                      Regards,
                      Uwe