7 Replies Latest reply on Aug 23, 2013 4:35 AM by indegn5

    Need a stop block in my script

    indegn5 Level 1

      Hi Forum,,

       

      I was very helpfull to learn from vamitul and Jarek previous thread help...

       

      but still i'm lagging here and my mind blocked....

       

      my script now find for the previous paragraph last character content ":" If yes, it will change all the bullets paragraphs first letter to caps...

       

      what happening is, it convert all the first Letters in bullet paragraph to caps...

       

      So now the stop block is needed to check, & stop changing the bullet first letter to uppercase if the previous paragraphs end character is not equal to ":"

       

       

      var oDoc = app.activeDocument;

      arr = [];

       

          var myNextPara = oDoc.textFrames.everyItem().getElements();

          for(k = 0; k<myNextPara.length; k++)  {

              myReturn = myNextPara[k].parentStory.paragraphs.firstItem(myNextPara[k].paragraphs[0])

      if(myReturn.isValid) {

          if(myReturn.bulletsAndNumberingListType !== ListType.BULLET_LIST &&

          myReturn.lines.lastItem().words.lastItem().characters.lastItem().contents == ":"&&

          myReturn.paragraphs.nextItem(myNextPara[k].paragraphs[0]).bulletsAndNumberingListType == ListType.BULLET_LIST)

       

      {

      changeCase();

      }

      if {myReturn.lines.lastItem().words.lastItem().characters.lastItem().contents !== ":") {

      exit

      } } }

       

      function changeCase() {

      app.findGrepPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;

      app.findGrepPreferences.findWhat = "^(\\l)";

       

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

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

       

      finds[i].contents=finds[i].contents[0].toUpperCase();

      }}

       

      Screen Shot 2013-08-22 at 14.14.44.png

        • 1. Re: Need a stop block in my script
          Jump_Over Level 5

          Hi,

           

          Two things:

          1. your way to go to changeGrep is really overcomplicated, but if you go there:

          2. call changeGrep for found paragraph only, not for whole document (para.changeGrep()).

           

          I would do it this way:

          - findGrep with findWhat set to ":\\s*$" for whole doc ( doc.findGrep());

          - iterate through and check if nextPara.bulletsAndNumberingListType = ListType.BULLET_LIST;

          - if your condition is true ==> nextPara.words[0].characters[0].changecase(ChangecaseMode.UPPERCASE);

           

          should be good enough

           

          Jarek

          • 2. Re: Need a stop block in my script
            Jump_Over Level 5

            Hi,

             

            Code for above with small modification

            (find Grep both paragraphs at once):

             

            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.findWhat = ":\\s*\r.";     // to match 2 paras - end & start
            
            var myDoc = app.activeDocument,
            mFound = myDoc.findGrep(),
            len = mFound.length;
            
            while (len--) {
                      currPara = mFound[len].paragraphs[0];
                      nextPara = mFound[len].paragraphs[1];
                 if (nextPara.bulletsAndNumberingListType == ListType.BULLET_LIST &&
                                currPara.bulletsAndNumberingListType != ListType.BULLET_LIST)
                                nextPara.words[0].characters[0].changecase(ChangecaseMode.UPPERCASE);
                 }
            app.findGrepPreferences = app.changeGrepPreferences = null;
            

             

            Jarek

            PS: if it keeps on rainin', levee's goin' to break

            08. Led Zeppelin - When The Levee Breaks

            • 3. Re: Need a stop block in my script
              indegn5 Level 1

              HI Jarek!!!

               

              Many many   thanks..

              Well, now it check and apply for the first two paragraphs only, how about for the following lines after paragraphs[1], till the paragraph [0] again start....":\\s*\r.";

              thanks for the support and smartest idea.....

              • 4. Re: Need a stop block in my script
                Jump_Over Level 5

                Hi,

                 

                Let me ask you once more about a goal:

                - it should find ":" at the end of "no bullets" para and change case of 1st letter of the next para if it is with "bullet", or

                - it should find ":" at the end of "no bullets" para and change case of 1st letter of every next para with bullet, stopping this at the and of bullets paras.

                 

                Jarek

                • 5. Re: Need a stop block in my script
                  indegn5 Level 1

                  Many many apologize for the confusions and many thanks for the patience in replying me......

                   

                  & supporting me....

                   

                  I do want to change the first character of every  paragraphs which is bullets and numbering:ListType.BULLETS format, following the paragraph, which has ":" at the end.

                   

                  and not to the bullets and numbering paragraphs following the paragraph which doesnt have ":" at the end....

                   

                  - it should find ":" at the end of "no bullets" para and change case of 1st letter of every next para with bullet, stopping this at the and of bullets paras.

                   

                  Many thanks Jarek,....

                  • 6. Re: Need a stop block in my script
                    Jump_Over Level 5

                    Hi,

                     

                    so lets include a function paraStepper():

                     

                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    app.findGrepPreferences.findWhat = ":\\s*\r.";     // to match 2 paras - end & start
                    
                    var myDoc = app.activeDocument,
                    mFound = myDoc.findGrep(),
                    len = mFound.length, currPara;
                    
                    while (len--) {
                         currPara = mFound[len].paragraphs[0];
                         if (currPara.bulletsAndNumberingListType != ListType.BULLET_LIST){
                                        currPara = paraStepper(currPara);
                                        while (currPara) {
                                                  currPara.words[0].characters[0].changecase(ChangecaseMode.UPPERCASE);
                                                  currPara = paraStepper(currPara);
                                                  }
                                        }
                         }
                     function paraStepper (para){
                               var mRes = false,
                               story = para.parentStory,
                               next = story.paragraphs.nextItem(para);
                               if (next.isValid && next.bulletsAndNumberingListType == ListType.BULLET_LIST)
                                        mRes = next;
                              return mRes;
                               }
                    app.findGrepPreferences = app.changeGrepPreferences = null;
                    

                     

                    Jarek

                    • 7. Re: Need a stop block in my script
                      indegn5 Level 1

                      I'm feeling too guilty to steal all your hardworks.... however, i  feel so proud in learing something that is not in my mind  <==> FROM YOU... 

                       

                      A bare mind of mine.. breaking my skull, to clear the clay blocks of  all the veins, in my brain,... and to store a wonderfull ideas of yours....

                       

                      Great & I'll give a treat for this treat....

                       

                       

                      Many thanks Jarek!!!!.