4 Replies Latest reply on Sep 17, 2013 1:35 AM by Sathya Rani M

    Reg.Apply paragraph style

    Sathya Rani M

      Hi All,

       

      Can you please anybody help me that how to apply the paragraph style which is available in Indesign with case insensitive in find/change grep options.

       

      I have tried with below code but the style applying only with case sensitive.

       

                myStyleName = myString.substring(1, myString.length-1);

                  if(myDocument.paragraphStyles.item(myStyleName) == "[object ParagraphStyle]")

                  {

                      myStyle = myDocument.paragraphStyles.item(myStyleName);

                      myName = myStyle.name;

                     

                      app.findChangeTextOptions.caseSensitive = false;

                      app.changeTextPreferences.appliedParagraphStyle = myStyle;

                      myDocument.changeText();

                      app.changeTextPreferences = NothingEnum.nothing;

                      app.changeTextPreferences.changeTo = "";

                      myDocument.changeText();

                      app.changeTextPreferences = NothingEnum.nothing;

       

                }

       

      Please help me to figure out this issue.

       

      Thanks in advance.

       

      Regards,

      Sathya Rani M

        • 1. Re: Reg.Apply paragraph style
          Jump_Over Level 5

          Hi,

           

          Your code in current version makes one go cross-eyed.

           

          - you are looking for find/change grep options but code is setting find/change text options;

          - where is yours "findWhat" set?

          - you can't execute changeText() (even twice...) with findWhat omitted;

          - what exactly case sensitive is according to?

           

          Be more accuracy, pls.

           

          Jarek

          • 2. Re: Reg.Apply paragraph style
            Sathya Rani M Level 1

            Hi Jarek,

             

            Thank you for your reply. Actually I need to find the style name with tag from activeDocument.

            For eq. if <lrh> or <LRH> found in activeDocument then find the "lrh" style available in Indesign and apply.

             

            Here is my full code. Please look into it.

             

            var myDocument = app.activeDocument;

            var myDocument = app.documents.item(0);

            app.findGrepPreferences = NothingEnum.nothing;

            app.changeGrepPreferences = NothingEnum.nothing;

            app.findChangeTextOptions.caseSensitive = false;

            app.findGrepPreferences.findWhat = "(?i)^<\\s*\\w+\\s*>";

            var myFoundItems = myDocument.findGrep();

             

             

            if(myFoundItems.length != 0)

                {

             

                    var myFoundTags = new Array;

                    for(var myCounter = 0; myCounter<myFoundItems.length; myCounter++)

                    {

                        myFoundTags.push(myFoundItems[myCounter].contents);

                    }

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

                    {

                        myString = myFoundTags[i];

                        app.findTextPreferences.findWhat = myString;

                        myStyleName = myString.substring(1, myString.length-1);

                       

                        if(myDocument.paragraphStyles.item(myStyleName) == "[object ParagraphStyle]")

                        {

                            myStyle = myDocument.paragraphStyles.item(myStyleName);

                            myName = myStyle.name;

                           

                            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;

                            app.changeTextPreferences.appliedParagraphStyle = myStyle;

                            myDocument.changeText();

                            app.changeTextPreferences = NothingEnum.nothing;

                            app.changeTextPreferences.changeTo = "";

                            myDocument.changeText();

                            app.changeTextPreferences = NothingEnum.nothing;

                    }

                }

            }

             

            But it is applying style only if "lrh" is present. It should be find case insensitive. please help me out.

             

            Thank you.

             

            ~Sathya Rani M

            • 3. Re: Reg.Apply paragraph style
              Jump_Over Level 5

              Hi,

               

              it is finding case insensitive but after this is trying to match a para style name with "findWhat" string (which vary).

               

              Is your style names always lowercase?

               

              If yes modify:

              ...

              myStyleName = myString.substring(1, myString.length-1).toLowerCase();

              ...

               

              Jarek


              1 person found this helpful
              • 4. Re: Reg.Apply paragraph style
                Sathya Rani M Level 1

                Hi Jarek,

                 

                The suggested case working is fine. I have solved the issue by treating the style names with Uppercase as you saying in lowercase.

                 

                Thank you very much for your support!

                 

                ~Sathya Rani M