7 Replies Latest reply on Jul 16, 2010 7:03 AM by Peter Kahrel

    Function for selecting paragraph style (including groups) JS

    TᴀW Adobe Community Professional & MVP

      Hi,

       

      Here's a function that will create a dropdown box and let you select any paragraph style in the document. It works with paragraph styles in groups. If Cancel is pressed, the function returns -1, else it returns the selected paragraph style.

       

      To call the function, use: myStyle = SelectParagraph();

       

      Nothing very spectacular, but I couldn't find any documentation regarding dealing with paragraph groups, so I thought I'd pass this on. Works with InDesign CS4.

       

      If anyone's got a better way of doing this, I'd be interested to hear.

       

      Ariel

       

       

       

      function SelectParagraph(){
      mydialog = app.dialogs.add({name:"Paragraphs", canCancel:true});
      myStyles = mydoc.allParagraphStyles;
      var mystring = [];
      for (aa = 0; aa < myStyles.length; aa ++){
      mystring[aa] = myStyles[aa].name;
      if (myStyles[aa].parent.constructor.name == "ParagraphStyleGroup") mystring[aa]+=" ["+myStyles[aa].parent.name+"]";
      }
      with (mydialog.dialogColumns.add()){
      staticTexts.add({staticLabel:"Please choose:"});
      }
      with (mydialog.dialogColumns.add()){
      mymenu = dropdowns.add({stringList:mystring, selectedIndex:0});
      }
      if (mydialog.show()) myresult = myStyles[mymenu.selectedIndex]}
      else myresult =-1;
      mydialog.destroy();
      return(myresult);
      }