5 Replies Latest reply on Feb 25, 2013 1:13 AM by s_ashok

    Find & Replace Text then apply ParaStyle

    FastTonni

      Hi Everyone,

       

      Any trick we can find text like "[FT], [FBL], [FISH]" and apply paragraph style "Footnote, BList, FISH_Text" one time.

       

      we have all MS-Files goes these type of circumstances, no any paragraph style apply in these MS-Files.

      Screen shot 2012-03-28 at 5.03.52 PM.png

      Thank you! I appreciate your help and explanation Adv.

        • 1. Re: Find & Replace Text then apply ParaStyle
          [Jongware] Most Valuable Participant

          I see you asked this a week ago as well. Sorry for not noticing -- that post must have disappeared from the front page real quick.

           

          This does not need scripting per se. Using GREP Find/Change, search for this:

           

          \[FT\](.)

           

          and replace with this:

           

          $1

           

          -- with your paragraph style set in the Change To Format field.

           

          Untried script to do lots of these (warning: I'm making this up as I type):

           

           

          var changelist = [ [ "FT", "Footnote"], [ "FBL", "BList"], ["FISH", "FISH_Text"] ];
           app.findGrepPreferences = null;
           app.changeGrepPreferences = null;
           
           app.changeGrepPreferences.changeTo = "$1";
           
          for (i=0; i<changelist.length; i++)
          {
            app.findGrepPreferences.findWhat = "\\["+changelist[i][0]+"\\]";
            app.changeGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item(changelist[i][1]);
            app.activeDocument.changeGrep();
          }
          
          • 2. Re: Find & Replace Text then apply ParaStyle
            FastTonni Level 1

            Hi Jongware Sir,

             

            Thanks so much for getting this done so quick i am really sorry, about this (late answering). Your code so simply great you are my hero. You made me a very happy person!. Sir one more question i am very new both (InDesign/JS) could you please tell me how i learn JS you have any suggestion/source/PDF/Tutt.

             

            Thank you verrrrrrry verrrrrrry much once again! Kudos to you.

            • 3. Re: Find & Replace Text then apply ParaStyle
              [Jongware] Most Valuable Participant

              You can learn a lot by hanging around on this forum a lot.

               

              .. Second best, however, is downloading Adobe's Javascript Guides, under Scripting Resources: http://www.adobe.com/products/indesign/extend.displayTab2.html#Scriptingresources -- best is to first read the Intro to Scripting, and if you decide it's something you could use, try some of the stuff in the tutorial.

               

              (Edit)

               

              BTW, did you use manual Find/Change, or did my quick script actually work?

              1 person found this helpful
              • 4. Re: Find & Replace Text then apply ParaStyle
                FastTonni Level 1

                Sir,

                Thank you so much once again!

                • 5. Re: Find & Replace Text then apply ParaStyle
                  s_ashok Level 1

                  Find and replace the text & apply paragraph style for indesign CS2.

                   

                   

                  Hai below script are working in cs4 - cs5.5. i need to run the script in indesign cs2.

                  can you please help.

                   

                   

                   

                  Main();

                   

                   

                   

                  function Main() {

                   

                      var foundItem;  

                   

                      var doc = app.activeDocument;

                   

                   

                   

                      //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

                   

                  app.findTextPreferences.findWhat = "^p";

                   

                   

                   

                   

                   

                   

                   

                         //app.findTextPreferences.appliedParagraphStyle = "head";

                   

                    

                   

                      var foundItems = doc.findText();

                   

                      

                   

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

                   

                          foundItem = foundItems[i];

                   

                          foundItem.applyParagraphStyle(doc.paragraphStyles.item("content body indent"), false);

                   

                            

                   

                      }

                   

                       app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

                   

                       var myDocument = app.activeDocument;

                   

                  //Clear the find/change text preferences.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                  //Set the find options.

                   

                  app.findChangeTextOptions.caseSensitive = false;

                   

                  app.findChangeTextOptions.includeFootnotes = false;

                   

                  app.findChangeTextOptions.includeHiddenLayers = false;

                   

                  app.findChangeTextOptions.includeLockedLayersForFind = false;

                   

                  app.findChangeTextOptions.includeLockedStoriesForFind = false;

                   

                  app.findChangeTextOptions.includeMasterPages = false;

                   

                  app.findChangeTextOptions.wholeWord = false;

                   

                  //Search the document for the string "copy" and change it to "text".

                   

                   

                   

                  app.findTextPreferences.findWhat = "^p";

                   

                   

                   

                  app.changeTextPreferences.changeTo = "^p";

                   

                  myDocument.changeText();

                   

                  //Clear the find/change text preferences after the search.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                   

                   

                  }

                   

                   

                   

                  abc();

                   

                   

                   

                  function abc() {

                   

                      var foundItem;  

                   

                      var doc = app.activeDocument;

                   

                   

                   

                      //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

                   

                  app.findTextPreferences.findWhat = "*";

                   

                   

                   

                   

                   

                   

                   

                         //app.findTextPreferences.appliedParagraphStyle = "head";

                   

                    

                   

                      var foundItems = doc.findText();

                   

                      

                   

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

                   

                          foundItem = foundItems[i];

                   

                          foundItem.applyParagraphStyle(doc.paragraphStyles.item("RealEstate"), false);

                   

                            

                   

                      }

                   

                       app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

                   

                       var myDocument = app.activeDocument;

                   

                  //Clear the find/change text preferences.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                  //Set the find options.

                   

                  app.findChangeTextOptions.caseSensitive = false;

                   

                  app.findChangeTextOptions.includeFootnotes = false;

                   

                  app.findChangeTextOptions.includeHiddenLayers = false;

                   

                  app.findChangeTextOptions.includeLockedLayersForFind = false;

                   

                  app.findChangeTextOptions.includeLockedStoriesForFind = false;

                   

                  app.findChangeTextOptions.includeMasterPages = false;

                   

                  app.findChangeTextOptions.wholeWord = false;

                   

                  //Search the document for the string "copy" and change it to "text".

                   

                   

                   

                  app.findTextPreferences.findWhat = "*";

                   

                   

                   

                  app.changeTextPreferences.changeTo = "";

                   

                  myDocument.changeText();

                   

                  //Clear the find/change text preferences after the search.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                   

                   

                  }

                   

                   

                   

                   

                   

                   

                   

                  ab();

                   

                  function ab () {

                   

                      var foundItem;  

                   

                      var doc = app.activeDocument;

                   

                   

                   

                      app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

                   

                      app.findTextPreferences.findWhat = " ^ ";

                   

                  app.changeTextPreferences.changeTo = " ";  

                   

                      //app.findTextPreferences.appliedParagraphStyle = "head";

                   

                    

                   

                      var foundItems = doc.findText();

                   

                    

                   

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

                   

                          foundItem = foundItems[i];

                   

                          foundItem.applyParagraphStyle(doc.paragraphStyles.item("day"), false);

                   

                           

                   

                      }

                   

                   

                   

                      app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

                   

                       var myDocument = app.activeDocument;

                   

                  //Clear the find/change text preferences.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                  //Set the find options.

                   

                  app.findChangeTextOptions.caseSensitive = false;

                   

                  app.findChangeTextOptions.includeFootnotes = false;

                   

                  app.findChangeTextOptions.includeHiddenLayers = false;

                   

                  app.findChangeTextOptions.includeLockedLayersForFind = false;

                   

                  app.findChangeTextOptions.includeLockedStoriesForFind = false;

                   

                  app.findChangeTextOptions.includeMasterPages = false;

                   

                  app.findChangeTextOptions.wholeWord = false;

                   

                  //Search the document for the string "copy" and change it to "text".

                   

                   

                   

                  app.findTextPreferences.findWhat = "^";

                   

                   

                   

                  app.changeTextPreferences.changeTo = "";

                   

                  myDocument.changeText();

                   

                  //Clear the find/change text preferences after the search.

                   

                  app.findTextPreferences = NothingEnum.nothing;

                   

                  app.changeTextPreferences = NothingEnum.nothing;

                   

                   

                   

                  }