4 Replies Latest reply on Jan 12, 2017 1:28 AM by Pete Stan

    Apply custom Paragraph Style to [No Paragraph]

    Pete Stan

      Hi all,

       

      I am looking for examples how to apply own Body Text Paragraph Style to [No Paragraph] Style. The Body Text is a part of Group EN:

      Screen Shot 2017-01-11 at 13.52.06.png

       

       

       

       

      Normally I would use Find/Change dialog but I believe there is a better way with scripting?

      Screen Shot 2017-01-11 at 13.54.27.png

        • 1. Re: Apply custom Paragraph Style to [No Paragraph]
          Obi-wan Kenobi Adobe Community Professional

          Hi,

           

          var myDoc = app.activeDocument,
          myParaStylesGroup = myDoc.paragraphStyleGroups.item('EN'),
          myParaStyle = myParaStylesGroup.paragraphStyles.item('Body Text');
          
          
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles[0];
          app.changeGrepPreferences.appliedParagraphStyle = myParaStyle;
          myDoc.changeGrep();
          app.findGrepPreferences = app.changeGrepPreferences = null;
          

           

          (^/)

          1 person found this helpful
          • 2. Re: Apply custom Paragraph Style to [No Paragraph]
            Laubender Adobe Community Professional & MVP

            Pete Stan wrote:

             

            … Normally I would use Find/Change dialog but I believe there is a better way with scripting?

            Hi Pete,

            why do you believe that scripting is a better way?
            Would you like to add something to the process by scripting what Find/Change cannot do?

             

            Regards,
            Uwe

            • 3. Re: Apply custom Paragraph Style to [No Paragraph]
              Pete Stan Level 1

              Works!

               

              I was tinkering :

              try{ 
              app.activeDocument.textFrames[0].insertionPoints[0].select(); 
              
              var pStyleGroup = app.activeDocument.paragraphStyleGroups.itemByName('EN');
              var titleStyle = pStyleGroup.paragraphStyles.itemByName('Body Text')
              
              app.activeDocument.paragraphs[0].applyParagraphStyle (app.activeDocument.paragraphStyles.item ("Body Text", true));
              }catch(e){};
              

               

              How about 'try': if for instance my Paragraph style will be different and I don't wanna see the error thrown by JavaScript? (will manually apply the style with that different name afterwards)

              • 4. Re: Apply custom Paragraph Style to [No Paragraph]
                Pete Stan Level 1

                Yes, To make my life easier!

                I have already a script that places a Word Document, auto-flows on A4, runs Jongware's PrepText, asks me to load the styles and now I can skip the step I was performing manually