3 Replies Latest reply on Jul 12, 2016 8:49 PM by karthiks94217840

    Insert "Discretionary Hyphen" before hyphen-nit words

    karthiks94217840 Level 2

      Dear All Friends,

       

      @Trevor (super man): I need one more help.

       

      I need to insert "Discretionary Hyphen" for first highlight hyphen-nit words before only (first character before). I was try, but i can't done that process. see below my work out code. Please suggest me friend.

       

      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[5];
                          }
      
      
      //****************************** Problem Start here ******************************************************************************
      
      
                          for (j = i - hyphenatetedLen; j > i; j++) {
                              lastWords[j].insertionPoints[0].contents = "\~";
                          }                    
                          alert(lastWords[j].contents);
                          
      //****************************** Problem End here ******************************************************************************                    
                      
                      }
                      hyphenateted = [];
                  }
             }
          }
      }
      app.doScript(color3PlusHyphenateted, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'color3PlusHyphenateted');
      

       

       

      Thanks in Advance

        • 1. Re: Insert "Discretionary Hyphen" before hyphen-nit words
          csm_phil Level 4

          Hi Karthiks94217840,

           

          If you use the special characters, then you have to follow this type. I modified your alert message like below.

           

                          
          alert(lastWords[0].insertionPoints[0].contents = SpecialCharacters.DISCRETIONARY_HYPHEN);  
          
          
          
          

           

          thx,

          csm_phil

          • 2. Re: Insert "Discretionary Hyphen" before hyphen-nit words
            karthiks94217840 Level 2

            Hi csm_Phil & Friends,

             

            Sorry for the late replay!

             

            I have modified my code as per your above instruction (Insert "DISCRETIONARY_HYPHEN" - working fine). But, i have faced one problem.

             

            For the code "DISCRETIONARY_HYPHEN" insert the first hyphen-nit word before only working fine.

             

            Otherwise, following all hyphen-nit (set) words before wrongly insert for "DISCRETIONARY_HYPHEN".

            (One and one character before). I don't now how to control this problem. Please suggest friends.

             

            Correct insert  "DISCRETIONARY_HYPHEN":

             

            1 set:

            1.png

             

            Wrong insert  "DISCRETIONARY_HYPHEN":

             

            2 & 3 sets:

            2.png

             

            I have place the below my problem coding only. This script full coding is above (Your reference):

             

            //****************************** Problem Start here ******************************************************************************

                                                         

                                        for (k = i - hyphenatetedLen; k > i; k++) {

                                        lastWords[k].insertionPoints[0].contents = SpecialCharacters.DISCRETIONARY_HYPHEN;  

                                        }                   

            //~                              alert(lastWords[j].contents);

                                            lastWords[k].insertionPoints[0].contents = SpecialCharacters.DISCRETIONARY_HYPHEN;

             

            //****************************** Problem End here ******************************************************************************                    

            Please help me friends.

             

            Thanks in Advance

            • 3. Re: Insert "Discretionary Hyphen" before hyphen-nit words
              karthiks94217840 Level 2

              Dear Friends,

               

              Please replay my above question?

               

              Thanks in Advance