7 Replies Latest reply on Jan 2, 2013 3:52 AM by shilpa25

    Total count of characters

    shilpa25

      Hi Forum,

       

      I have this script for alerting "the text filled with Magenta color & no. of occurrences".

       

      script, runs, it count the no. of occurrences of the fill color - thats right.... but the alert appears the many no. of times equal to no. of the characters filled with magenta color.

       

      my request is, can anyone tweak my script to "alert only once,... with the total no. of occurrences of magenta colour inside doc...

       

      var mydoc = app.activeDocument;

      var txts=mydoc.stories.everyItem().paragraphs.everyItem().characters.everyItem().getElements( );

       

      for (i=0; i<txts.length; i++)

      {

      txt = txts[i];

           if (txt.fillColor.name == "Magenta copy")

           alert (txts.length);

           }

       

      Can anyone help on this please...

       

       

      thanks,

      shil.....

        • 1. Re: Total count of characters
          csm_phil Level 4

          Hi Shilpa25,

           

          I had modified your JS code, Please try this.

           

          I hope you expect this.

           

           

          var mydoc = app.activeDocument;
          
          var txts=mydoc.stories.everyItem().paragraphs.everyItem().characters.everyItem().getElements();
          
          var TotalCount = []; 
          
          for (i=0; i<txts.length; i++)
          {
              var txt = txts[i];
               if (txt.fillColor.name == "Magenta copy"){
                  TotalCount.push(txt);
                  }
              }
          alert(" total no. of occurrences of magenta colour inside doc: " + TotalCount.length);
          

           

           

          thx,

          csm_phil

           

          Message was edited by: csm_phil

          • 2. Re: Total count of characters
            shilpa25 Level 1

            thanks csm_phil,

             

            great work!...

             

            once more "how can i get page no. of the magenta copy, where it is present".

             

            could you please include the code is alert.

            • 3. Re: Total count of characters
              csm_phil Level 4

              Hi Shilpa,

               

              Can you please explain this requst manually, for example  if you get the char count is 25 in page 1, and another char count is 50 in page 3.

               

              25+50 = 75 magenta copy characrert in this document.

               

              1+3 = 4 I thinks, this is worng. What you expect?

               

              Otherwise Please explain clearly.

               

              For the first request answer is correct you have to select the correct answer or helpfull answer. Please keep this every post.

               

              thx,

              csm_phl.

              1 person found this helpful
              • 4. Re: Total count of characters
                shilpa25 Level 1

                Hi csm_phil,

                 

                please reject my previous post.. sorry for have made confusion...

                 

                finally i came to conclusion.... I m trying to get pageno, where the magenta copy colour is present... (assume the no. of document pages is 50.)

                 

                var mydoc = app.activeDocument;

                var txts=mydoc.stories.everyItem().paragraphs.everyItem().characters.everyItem().getElements( );

                var TotalCount = new Array;

                for (i=0; i<txts.length; i++)

                    txt = txts[i];

                     if (txt.fillColor.name == "Magenta copy"){

                         TotalCount.push(txts.parentTextFrames.parentPage.name) //something like this.... here I do something wrong...

                             alert(TotalCount);

                }

                 

                thanks,,, for your help csm_phil.....

                 

                shil...

                1 person found this helpful
                • 5. Re: Total count of characters
                  Laubender Adobe Community Professional & MVP

                  @shilpa25 – parentTextFrames is an Array.
                  For one single character the length of that array should be always 1.

                  For overset text it will be "undefined".

                   

                  So you have to write:

                  parentTextFrames[0].parentPage.name

                   

                   

                  Maybe it's unclear to me what you are looking for…

                  But what I do not understand is:

                   

                  Why not starting the script by iterating through the pages of the document and looking for the text by a Text search?

                   

                  If you only want to know if "magenta copy" is present on a particular page (and you do not want the amount of characters), you could break the search immediately one occurance is found on that page and go on to the next page…

                   

                  That would speed up the script considerably.

                   

                  Uwe

                  1 person found this helpful
                  • 6. Re: Total count of characters
                    Laubender Adobe Community Professional & MVP

                    Another comment about the snippets by shil:
                    The scope of the script seems too wide for me. With "parentPage" in conjunction with "stories.everyItem()" you'll get into trouble if you consider text frames on the pasteboard. Then "parentPage" is "null". You could handle that with an if-statement:

                     

                    if(myTextFrame.parentPage != null){
                    //do something…
                    };
                    

                     

                    But I think you are doing better with a Text search…

                     

                    Uwe

                    1 person found this helpful
                    • 7. Re: Total count of characters
                      shilpa25 Level 1

                      thanks laubender,

                       

                      i will try to implemend your corrections.....

                       

                      shil..