2 Replies Latest reply on Jul 28, 2016 1:51 AM by JustOneBren

    Paragraph Style from the Containing Box (Text)

    JustOneBren Level 1

      Easy one i'm sure but I cannot get it , need some help please.


      If my selection is the text:


      returns the Paragraph Style used.


      If my selection is the text box containing the text, how do i alert the Paragraph Style used inside the text box?


      Many Thanks, Bren

        • 1. Re: Paragraph Style from the Containing Box (Text)
          Laubender Adobe Community Professional & MVP

          Hi Bren,

          ask yourself, if you selected a bunch of paragraphs where different paragraph styles are applied:

          What would you expect that your alert will return?
          And what is actually returned?


          Then do your tests with a selected text frame:




          And finally loop through all the paragraphs of the text frame and its story.

          Note: $.writeln() will write the results to the JavaScript Console of the ExtendScript Toolkit (ESTK)


          var textFrame = app.selection[0];
          var textOfTextFrame = textFrame.texts[0];
          var textOfStoryOfTextFrame = textFrame.parentStory.texts[0];
          if(textOfTextFrame.paragraphs.length > 0)
               var paragraphs = textOfTextFrame.paragraphs.everyItem().getElements();
               for(var n=0;n<paragraphs.length;n++)
                    $.writeln( n+"\t"+paragraphs[n].appliedParagraphStyle.name );



          1 person found this helpful
          • 2. Re: Paragraph Style from the Containing Box (Text)
            JustOneBren Level 1

            Thanks Uwe,


            Had been looking for a few hours to try to get this but the closest I had was "alert(app.selection[0].appliedParagraphStyle.name)" and many other variations along the way that didn't work. As you said it's difficult with grabbing the box as it could contain 100 different fonts but I knew there had to be a way because "alert(app.selection[0].textStyleRanges.everyItem().fontStyle)" returned "Medium" (when on a selection with just one font) but couldn't quite find the answer by myself.


            It's for part of a script that finds any boxes with the Paragraph Style "Fab Tick" applied that has overset text (but appears 'completely' empty) and expands the box to fit. Below is the finished script if anyone finds it useful.


            var myFrame = app.activeDocument.allPageItems;

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

                       { if (myFrame[i] instanceof TextFrame && myFrame[i].contents == "")

                       { if (myFrame[i].texts[0].appliedParagraphStyle.name == "Fab Tick") // Replace if Paragraph Style found

                             {myFrame[i].textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH_PROPORTIONALLY

                               myFrame[i].textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY

                      }}}} catch(er){}


            Many Thanks for you help, my script is now working, Bren