11 Replies Latest reply on Jul 6, 2016 10:27 PM by sreekarthik.k@gmail.com

    How to highlight continue 3 line end hyphen-nit word

    karthiks94217840 Level 2

      Dear Friends,

       

      I need your help!

       

      How to highlight the continue 3 line end hyphen-nit word? Screenshot below.

       

      Screen+Shot+2016-02-12+at+11.22.00+PM.png

       

       

      I have highlight for all hyphen-nit word (below my code). But, i need to highlight for continue 3 line hyphen-nit words only. Otherwise no need single and double word hyphen highlight. Please suggest friends

       

      My code:

       

      var doc = app.activeDocument,    
          _stories = doc.stories;    
      for(var i=0;i<_stories.length;i++)    
      {    
              var _lines = _stories[i].lines;    
              for(var j=0;j<_lines.length;j++)    
              {    
                      if(_lines[j].words[-1].lines.length >= 2)  
                      {  
                              _lines[j].words[-1].fillColor = "Green";  
                          }  
                  }    
          } 
      

       

      Thanks in advance

        • 1. Re: How to highlight continue 3 line end hyphen-nit word
          karthiks94217840 Level 2

          Dear Friend,

           

          One quick question: I have recess the above question is possible to script? Yes or No.

           

          Thanks in Advance

          • 2. Re: How to highlight continue 3 line end hyphen-nit word
            karthiks94217840 Level 2

            Dear Friends,

             

            Please, give me any one solution? very urgent.

             

            That is possible?


            Thanks in Advance

            • 3. Re: How to highlight continue 3 line end hyphen-nit word
              Trevorׅ Adobe Community Professional

              Hi Karthiks

               

              If you are looking to highlight all occurrences of 3 or more consecutive hyphenated last words you can try.

              I'm not claiming it's a particularly efficient way of doing it.

              function color3PlusHyphenateted() {
                  var doc, stories, n, l, lastWords, firstWords, hyphenateted, e, i, lwl, HReg;
                  HReg = /HHH+/g;
                  doc = app.activeDocument;
                  stories = doc.stories.everyItem().getElements().slice(0);
                  l = stories.length;
                  for (n = 0; n < l; n++) {
                      lastWords = [0].concat([], stories[n].lines.everyItem().words[-1].getElements().slice(0));
                      firstWords = stories[n].lines.everyItem().words[0].getElements().slice(0);
                      lwl = lastWords.length;
                      hyphenateted = [];
                      for (i = 1; i < lwl; i++) {
                          hyphenateted[i] = (lastWords[i] === firstWords[i]) ? 'H' : '0';
                      }
              
                      hyphenateted = hyphenateted.join('');
                      while (e = HReg.exec(hyphenateted)) {
                          for (i = e.index + 1; i <= HReg.lastIndex; i++) {
                              lastWords[i].fillColor = doc.colors[3];
                          }
                      }
                      HReg.lastIndex = 0;
                  }
              }
              app.doScript(color3PlusHyphenateted,ScriptLanguage.JAVASCRIPT,undefined, UndoModes.ENTIRE_SCRIPT, 'color3PlusHyphenateted');
              

              If you only highlight all occurrences of exactly 3 consecutive hyphenated last words change the line

              HReg = /HHH+/g;
              

              to

              HReg = /HHH/g;
              

              Screen Shot 2016-07-05 at 16.54.40.png

               

              HTH

               

              Trevor

              • 4. Re: How to highlight continue 3 line end hyphen-nit word
                Trevorׅ Adobe Community Professional

                This is a more normal way to do it.

                function color3PlusHyphenateted() {
                    var doc, stories, n, l, lastWords, firstWords, hyphenateted, isHyphanated, i, j, lwl, hyphenatetedLen;
                    doc = app.activeDocument;
                    stories = doc.stories.everyItem().getElements().slice(0);
                    l = stories.length;
                    for (n = 0; n < l; n++) {
                        lastWords = [0].concat([], stories[n].lines.everyItem().words[-1].getElements().slice(0));
                        firstWords = stories[n].lines.everyItem().words[0].getElements().slice(0);
                        lwl = lastWords.length;
                        hyphenateted = [];
                        for (i = 0; i < lwl; i++) {
                            isHyphanated = (lastWords[i] === firstWords[i]);
                            if (isHyphanated) {
                                hyphenateted.push(lastWords[i]);
                            } else {
                                hyphenatetedLen = hyphenateted.length;
                                if (hyphenatetedLen > 2) {
                                    for (j = i - hyphenatetedLen; j < i; j++) {
                                        lastWords[j].fillColor = doc.swatches[6];
                                    }
                                }
                                hyphenateted = [];
                            }
                        }
                    }
                }
                app.doScript(color3PlusHyphenateted, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'color3PlusHyphenateted');
                
                
                • 5. Re: How to highlight continue 3 line end hyphen-nit word
                  Trevorׅ Adobe Community Professional

                  Edit above to correct a bug

                  • 6. Re: How to highlight continue 3 line end hyphen-nit word
                    karthiks94217840 Level 2

                    Dear Friend Trevor,

                     

                    Very very Thank you soooooo mach for you Trevor .

                     

                    Your coding is working super-good. Really, your are save my life. You are super.

                     

                    One more Thanks Thanks Thanks

                     

                    Thanks

                    • 7. Re: How to highlight continue 3 line end hyphen-nit word
                      karthiks94217840 Level 2

                      Dear Friends,

                       

                      One more help! The same thing for in above answer.

                       

                      @Trevor: I need to highlight for including all hard hyphens also. In below formula for find to all hard hyphens words. But, I don't now how to add that formula in your above code? (please use correct answer code).

                      @Formula: "\\w+[-~=~-~_]"

                       

                      @Example: Only for, both soft hyphen between hard hyphen will be come. That time i need to highlight for all 3 hyphen words (soft & hard hyphens). I have place screenshot for your reference.

                       

                      For highlight in the center word is hard hyphen word.

                      123.JPG

                      Thanks in Advance

                       

                       

                      • 8. Re: How to highlight continue 3 line end hyphen-nit word
                        Trevorׅ Adobe Community Professional

                        karthiks94217840 wrote:

                         

                        @Trevor: I need to highlight for including all hard hyphens also. In below formula for find to all hard hyphens words. But, I don't now how to add that formula in your above code? (please use correct answer code).

                        Thanks in Advance

                        I only read that bit afterwards so you'll have to do 

                        I prefer the 2nd answer.

                         

                        function color3PlusHyphenateted() {

                            var doc, stories, n, l, lastWords, firstWords, hyphenateted, isHyphanated, i, j, lwl, hyphenatetedLen, everyLastWord;

                            doc = app.activeDocument;

                            stories = doc.stories.everyItem().getElements().slice(0);

                            l = stories.length;

                            app.findGrepPreferences = app.changeGrepPreferences = null;

                            app.findGrepPreferences.findWhat = '\-$';

                            for (n = 0; n < l; n++) {

                                everyLastWord = stories[n].lines.everyItem().words[-1];

                                lastWords = [0].concat([], everyLastWord.getElements().slice(0));

                                everyLastWord = everyLastWord.findGrep();

                                everyLastWord = [0].concat([], everyLastWord);

                         

                                firstWords = stories[n].lines.everyItem().words[0].getElements().slice(0);

                                lwl = lastWords.length;

                         

                                hyphenateted = [];

                                for (i = 0; i < lwl; i++) {

                                    isHyphanated = ((everyLastWord[i] && everyLastWord[i].length) || (lastWords[i] === firstWords[i]));

                                    if (isHyphanated) {

                                        hyphenateted.push(lastWords[i]);

                                    } else {

                                        hyphenatetedLen = hyphenateted.length;

                                        if (hyphenatetedLen > 2) {

                                            for (j = i - hyphenatetedLen; j < i; j++) {

                                                lastWords[j].fillColor = doc.swatches[9];

                                            }

                                        }

                                        hyphenateted = [];

                                    }

                                }

                            }

                        }

                        app.doScript(color3PlusHyphenateted, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'color3PlusHyphenateted');

                        • 9. Re: How to highlight continue 3 line end hyphen-nit word
                          Trevorׅ Adobe Community Professional

                          Excuse the lack of code formatting above, Jives is playing up today!

                          • 10. Re: How to highlight continue 3 line end hyphen-nit word
                            karthiks94217840 Level 2

                            Dear Friend Trevor,

                             

                            Again and again - Thank you so mach for you Trevor .

                             

                            That coding also working super-good. You are super man.

                             

                            One more Thanks so mach

                             

                            Thanks

                            • 11. Re: How to highlight continue 3 line end hyphen-nit word
                              Level 1

                              While running the script it throw the below erro in the 10th line. Please advice.

                              Error.PNG