10 Replies Latest reply on Jul 25, 2014 4:45 AM by Johnwhite

    Why this script unfunction?

    Johnwhite Level 1

      Hi, everyone

       

      can you find the wrong syntax of this script, and help me to fix it?

       


      app.findGrepPreferences = app.changeGrepPreferences = null;
      var doc = app.activeDocument,    
          _selection = app.selection[0].words;    

      var ignoreWords = "a, an, and, the, to, with, in, on, as, of, or, at, into, by, from, their, then, for, are, that, is, be"; 


      app.findGrepPreferences.appliedParagraphStyle = "01 H1";

          finds = app.selection[0].findGrep();

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

          if(ignoreWords.indexOf(_selection[i].contents) == -1) 
          { 
              finds[i].texts[0].changecase(ChangecaseMode.titlecase);
      }
          }

          app.findGrepPreferences = app.changeGrepPreferences = null;

       

      John

        • 1. Re: Why this script unfunction?
          Jump_Over Level 5

          Hi,

           

          Does it return an error?

           

          The problem is with a logic, not with a syntax, I guess.

          How important is matching a paraStyle "01 H1"?

           

          Jarek

          • 2. Re: Why this script unfunction?
            Johnwhite Level 1

            Hi,

            Jarek

             

            I already have this script

             

            var doc = app.activeDocument,    

                _selection = app.selection[0].words;    

             

            var ignoreWords = "a, an, and, the, to, with, in, on, as, of, or, at, into, by, from, their, then, for, are, that, is, be"; 

             

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

                if(ignoreWords.indexOf(_selection[i].contents) == -1) 

                { 

                        _selection[i].changecase(ChangeCaseOptions.TITLECASE); 

                    } 

                }

             

            but I change it into as before

            aim to search the heading only

             

            so, it's important

             

            John

            • 3. Re: Why this script unfunction?
              Jump_Over Level 5

              Hi,

               

              so only change you need is line 8:

              //...
              if(_selection[i].appliedParagraphStyle == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1)
              //...
              
              

               

              I mean change in a code you had before

              Jarek

              • 4. Re: Why this script unfunction?
                Johnwhite Level 1

                Hi, Jarek

                 

                I changed it

                 

                but not anything response to me.


                app.findGrepPreferences = app.changeGrepPreferences = null;
                var doc = app.activeDocument,    
                    _selection = app.selection[0].words;    

                var ignoreWords = "a, an, and, the, to, with, in, on, as, of, or, at, into, by, from, their, then, for, are, that, is, be"; 


                app.findGrepPreferences.appliedParagraphStyle = "01 H1";

                    finds = app.selection[0].findGrep();

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

                if(_selection[i].appliedParagraphStyle == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1) 


                        finds[i].texts[0].changecase(ChangecaseMode.titlecase);
                }
                    }

                    app.findGrepPreferences = app.changeGrepPreferences = null;

                 

                John

                • 5. Re: Why this script unfunction?
                  Jump_Over Level 5

                  HI,

                   

                  I  ment to change a code you had before (post no 2) -  not the one you messed up.

                   

                  Jarek

                  • 6. Re: Why this script unfunction?
                    Johnwhite Level 1

                    Hi, Jarek

                     

                    you mea this one:

                     

                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    var doc = app.activeDocument,    
                        _selection = app.selection[0].words;    

                    var ignoreWords = "a, an, and, the, to, with, in, on, as, of, or, at, into, by, from, their, then, for, are, that, is, be"; 


                    app.findGrepPreferences.appliedParagraphStyle = "01 H1";

                        finds = app.selection[0].findGrep();

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

                    if(_selection[i].appliedParagraphStyle == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1) 


                            finds[i].texts[0].changecase(ChangecaseMode.titlecase);
                    }
                        }

                        app.findGrepPreferences = app.changeGrepPreferences = null;

                     

                    ????

                     

                    still nothing

                     

                    John

                    • 7. Re: Re: Why this script unfunction?
                      Jump_Over Level 5

                      Hi,

                       

                      I mean this one:

                      var doc = app.activeDocument,   
                          _selection = app.selection[0].words;   
                      
                      var ignoreWords = "a, an, and, the, to, with, in, on, as, of, or, at, into, by, from, their, then, for, are, that, is, be";
                      
                      for(var i=0;i<_selection.length;i++)
                      {
                          if(_selection[i].appliedParagraphStyle == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1)
                          {
                                  _selection[i].changecase(ChangeCaseOptions.TITLECASE);
                              }
                          }
                      

                       

                      line 8 is modified

                       

                      Jarek

                      • 8. Re: Why this script unfunction?
                        Johnwhite Level 1

                        Hi,

                         

                        Jarek

                         

                        I testedm but still nothing

                         

                        why?

                         

                        John

                        • 9. Re: Re: Why this script unfunction?
                          Chinnadk Level 4

                          Hi John,

                           

                          ".name" should be added in the 8th line with appliedParagraphStyle. Change the 8th line of Jarek's script as like below.

                           

                          if(_selection[i].appliedParagraphStyle.name == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1) 
                          
                          

                           

                          Regards,

                          Chinna

                          • 10. Re: Why this script unfunction?
                            Johnwhite Level 1

                            Thank you Chinna

                             

                            Now it's working!

                             

                            Thank you all guys

                             

                            John