5 Replies Latest reply on Jul 2, 2013 10:14 AM by tusharde

    Find selected paragraph style in the paragraph style panel

    tusharde

      Hi,

      Noob here. I just got into indesign scripting.

       

      I'm trying to a script that will add a few GREP styles to the currently selected paragraph style in the Paragraph Styles panel.

      My question is how do i find what the currently selected paragraph style is in the Para Styles panel? What is the javascript code for that?

       

      Any help will be much appreciated.

       

      Thanks

        • 1. Re: Find selected paragraph style in the paragraph style panel
          Jump_Over Level 5

          Hi,

           

          if text tool is inactive use:

           

          app.activeDocument.textDefaults.appliedParagraphStyle;
          

           

          otherwise:

           

          app.selection[0].appliedParagraphStyle;
          

           

          rgds

          Jarek

          • 2. Re: Find selected paragraph style in the paragraph style panel
            Laubender Adobe Community Professional & MVP

            You can only get that information, if you selected* some text with that paragraph style.

             

            Here an example:

             

            //To define a GREP Style we need 
            //1. a character style:
            var myChStyle = app.activeDocument.characterStyles[0]; //This is Character Style "[None]"
            
            //2. a GREP expression as string:
            var myGREPString = "\d+";
            
            //3. a paragraph style
            //For example the applied paragraph style from
            //the first paragraph of a selected text:
            
            var myAppliedParaStyle = app.selection[0].paragraphs[0].appliedParagraphStyle;
            
            
            //If you want to clear ALL GREP Styles already defined un-comment the following lines:
            
            //~ var allGREPStylesArray = myAppliedParaStyle.nestedGrepStyles.everyItem().getElements();
            
            //~ for(var n=allGREPStylesArray.length-1;n>=0;n--){
            //~     allGREPStylesArray[n].remove();
            //~     };
            
            //CAUTION: We did not check, if there are already some GREP-Styles defined!
            //The new GREP Style will be added to previously existing ones.
            
            //Now we add a new GREP Style to the paragraph style:
            myAppliedParaStyle.nestedGrepStyles.add({
            
                appliedCharacterStyle:myChStyle,
                grepExpression:myGREPString
            
                });
            

             


            *or found another way to target a piece of text.

            Example for the applied character style of the first insertion point of the first text frame on page one of the active document:

             

            myAppliedParaStyle = app.activeDocument.pages[0].textFrames[0].insertionPoints[0].appliedCharacterStyle;
            

             


            *or you know the paragraph style by name or by index order in the Paragraph Styles Panel.

             

            Example by Name:

             

            myParaStyle = app.activeDocument.paragraphStyles.itemByName("Plain_String_Of_The_Name_If_Not_In_Subdirectory");
            

             

            Uwe

            • 3. Re: Find selected paragraph style in the paragraph style panel
              Laubender Adobe Community Professional & MVP

              Ok. I was wrong.

               

              There is a way to get the selected paragraph style, if nothing is selected, but the name of the paragraph style in the panel.

               

              Thank you for that, Jarek!

              Uwe

              • 4. Re: Find selected paragraph style in the paragraph style panel
                tusharde Level 1

                Thanks. I'll give that a shot.

                • 5. Re: Find selected paragraph style in the paragraph style panel
                  tusharde Level 1

                  Thanks guys. Appreciate the responses. There are a few things here i can learn from. I'll mess around with them.