3 Replies Latest reply on Sep 6, 2013 3:21 AM by Kai Rübsamen

    How to find whole paragarph?

    Learner Learner

      Hi All,

       

      How to finding a word and getting a parent paragarph of the word.

       

      Regards,

      Learner

        • 1. Re: How to find whole paragarph?
          Mac_rk Level 2

          try below code

           

          var myDoc = app.activeDocument; 

          var pages=myDoc.pages;

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

                var page=pages[i];

                var pageItems=page.textFrames;

                for(var j=0;j<pageItems.length;j++){

                       app.findGrepPreferences = NothingEnum.nothing;

                       app.changeGrepPreferences = NothingEnum.nothing;

                       app.findGrepPreferences.findWhat = "word";

                       var myWord ;

                        myWord = pageItems[j].findGrep();

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

                            alert (myWord[i].insertionPoints[0].paragraphs[0].contents)

                        }

                    }

            }

          • 2. Re: How to find whole paragarph?
            Learner Learner Level 1

            Thank you so much Mac_rk your code realy works fine for me

             

            Regards,

            Learner

            • 3. Re: How to find whole paragarph?
              Kai Rübsamen Adobe Community Professional

              Just for the record: I’m a beginner in JS-Scripting, but I would suspect that there is no need to iterate through pages and pageItems, if you use a GREP-search.

               

              For me this works as well:

               

              var curDoc = app.activeDocument;

               

              app.findGrepPreferences = app.changeGrepPreferences = null;

              app.findGrepPreferences.findWhat = "word";

              var fund = app.findGrep();

               

              for (var f=0; f<fund.length; f++) {

                  var curWord = fund[f];

                  alert(curWord.paragraphs[0].contents);

              }

               

              best

              Kai