4 Replies Latest reply on Jul 28, 2014 6:08 AM by AsOne

    Find fill colour frames in images

    AsOne

      Hi All,

       

      I am trying to find fill colour frames in images, my code is giving error as Object does not support the property or method "allPageItem"

       

      could anyone solve this please.

       

       

      var COLOR_NAME="color name string";

           var currentPageItem;

           for (var currentPageItem=0;currentPageItem<app.activeDocument.allPageItems.length;currentPageItem) {

                currentPageItem=app.activeDocument.allPageItem[currentPageItem];

                if ((currentPageItem instanceof Rectangle || currentPageItem instanceof Polygon)

                          && currentPageItem.contentType==ContentType.GRAPHIC_TYPE

                          && currentPageItem.fillColor==COLOR_NAME) { // do what you want

                      app.activeDocument.selection=currentPageItem;

                     alert("This box has fill color!!");

                }

           }

       

       

      Thanks in advance

      Steve

        • 1. Re: Find fill colour frames in images
          Chinnadk Level 4

          Hi Steve,

           

          1. Increment operater is missing in the loop.

                    currentPageItem++

          2. app.activeDocument.allPageItem[currentPageItem] this line 's' is missing it should be:

                    app.activeDocument.allPageItems[currentPageItem]

          3. in if condition this currentPageItem.fillColor==COLOR_NAME should be changed to:

                         currentPageItem.fillColor==app.activeDocument.colors.item("color name string")

           

          Regards,

          Chinna

          • 2. Re: Find fill colour frames in images
            AsOne Level 1

            Hi Chinna,

             

            Thanks for your reply, the code is working with your idea like

             

            var COLOR_NAME="Red";

            //~ var COLOR_NAME=app.activeDocument.swatches;

                 var currentPageItem;

                 for (var currentPageItem=0;currentPageItem<app.activeDocument.allPageItems.length;currentPageItem) {

                     currentPageItem=app.activeDocument.allPageItems[currentPageItem++]

                      if ((currentPageItem instanceof Rectangle || currentPageItem instanceof Polygon)

                                && currentPageItem.contentType==ContentType.GRAPHIC_TYPE

                                && currentPageItem.fillColor==app.activeDocument.colors.item(COLOR_NAME)) { // do what you want

                            app.activeDocument.selection=currentPageItem;

                           alert("This box has fill color!!");

                      }

                 }

            ---------------

             

            Now, how can I find a fill colour in images (all colours which applied in images), could you change it please.

             

            Thanks in advance

            Steve

            • 3. Re: Re: Find fill colour frames in images
              Chinnadk Level 4

              Hi Steve,

               

              Try this.

               

              var doc = app.activeDocument,
                  pi = doc.pageItems.everyItem().getElements();
              for(var i =0;i<pi.length;i++)
              {
                      if((pi[i] instanceof Rectangle||pi[i] instanceof Polygon) && pi[i].contentType==ContentType.GRAPHIC_TYPE &&pi[i].fillColor.name!="None")
                      {
                              doc.selection=pi[i];
                              alert("This box has fill color : " + pi[i].fillColor.name)
                          }
                  }
              

               

              Regards,

              Chinna

              • 4. Re: Re: Find fill colour frames in images
                AsOne Level 1

                Hi Chinna,

                 

                You are great, Thank you so much. It's working fantastic

                 

                Thanks

                Steve