3 Replies Latest reply on Feb 16, 2015 9:21 AM by djbgraphicdesign

    Applying a paragraph style to text frames in document

    djbgraphicdesign Level 1

      Hello everyone! Not sure what I am doing wrong here, and I am having trouble finding examples of this online, so I thought I would ask.

       

       

       

       

      var docRef = app.activeDocument;

       

      var textRef = docRef.textFrames;

       

      var paraStyle = docRef.paragraphStyles.getByName ("LeftIndent");

       

      var iCount = textRef.paragraphs.length; //This is the error that shows up.

       

      for(var i=0; i<iCount; i++) {

       

      paraStyle.applyTo(textRef.paragraphs[i], true);

       

      }

       

      redraw();

       

       

       

       

       

       

      Thanks in advance!!

        • 1. Re: Applying a paragraph style to text frames in document
          Qwertyfly... Level 4

          at a glance I would say you need to loop textframes and within that loop paragraphs.

          • 2. Re: Applying a paragraph style to text frames in document
            djbgraphicdesign Level 1

            Thanks imagecollection, I almost have it figured out now. I still get an error every so often. I am just making random text boxes with random type in it, and sometimes I will get an error. I have no idea why the particular text box makes it have an error, when I delete it the error goes away, I am not doing anything different to it that I know of.

             

            var docRef = app.activeDocument;

             

            var textRef = docRef.textFrames;

             

            var paraStyle = docRef.paragraphStyles.getByName ("LeftIndent");

             

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

               

                for(var j = 0; j < textRef[i].paragraphs.length; j++) {

               

                paraStyle.applyTo(textRef[i].paragraphs[j], true);   //Some of the time I get an error here when I make a text box it doesn't like?

             

                }

             

            }

             

             

            redraw();

            • 3. Re: Applying a paragraph style to text frames in document
              djbgraphicdesign Level 1

              Thanks again for getting me on the right track. This seems to work for me.

               

              var docRef = app.activeDocument;

               

              var textRef = docRef.textFrames;

               

              var paraStyle = docRef.paragraphStyles.getByName ("ENERGETIC");

               

               

              //in the dialog box make a custom option that will by pass the paragraph styles

               

               

              paraStyle.characterColor = docRef.swatches[2];

               

              for(var i=textRef.length-1; i >= 0; i--) {

                

                try {

                

                 paraStyle.applyTo(textRef[i].paragraphs[0], true);

                 textRef[i].createOutline()

                

              }

               

               

              catch (e) {

                  textRef[i].remove()

                  }

              }

               

              //worry about the color after the outines have been created. Then it will be a group item.

               

              redraw();

               

               

               

              In my template file I use for this I have it set up as a bunch of 1 line story connected text boxes so I only have 1 paragraph in each. Now with this script I can copy and paste an excel spreadsheet of names, and each name will be individually grouped and that will be super helpful.