4 Replies Latest reply on Nov 12, 2011 7:11 AM by winterm

    applying paragraph styles

    winterm Level 5

      hi all,


      playing around with some very simple script:



      mySel = app.selection[0];
      mySel.paragraphs[0].insertionPoints[0].paragraphs[0].appliedParagraphStyle = "myPStyle1";
      mySel.paragraphs[0].insertionPoints[-1].paragraphs[0].appliedParagraphStyle = "myPStyle2";
      mySel.paragraphs[0].insertionPoints[-2].paragraphs[0].appliedParagraphStyle = "myPStyle3";


      script applies paragraph style myPStyle1 to paragraph with text cursor inserted, then myPStyle2 to next paragraph, and then... I'm stuck here.

      Line 3 applies myPStyle3 to the first paragraph again, instead of expected next (3rd) one...


      I thought I can expand the sequence as far as I need, but I can not?

      I feel I don't catch something very basic here...


      any tip?

      or another source, where such silly questions are answered?

      thank you!

        • 1. Re: applying paragraph styles
          John Hawkinson Level 5

          This is not the correct approach. It only works by accident.


          mysel.paragraphs[0].insertionPoints are all the insertion points in the current paragraph. If there are 100 characters, then there are 101 insertPoints (on each side of each character). insertionPoint[0] is to the left of the first characer, [1] is to the right of the first character, [2] is to the right of the 2nd character, etc., up to [101] to the right of the last character.


          insertionPoints[-1] refers to the last insertionPoint, [101], which is actually after the paragraph, per se, so formats the next paragraph.

          insertionPoints[-2] refers to the 2nd-to-last insertionPoint, [100], which is the the left of the last character.


          I'm not sure what the best way to deal with this is. Perhaps:


          p = mySel.paragraphs[0]; p.appliedParagraphStyle="myPstyle1";
          p = p.insertionPoints[-1].paragraphs[0]; p.appliedParagraphStyle="myPstyle2";
          p = p.insertionPoints[-1].paragraphs[0]; p.appliedParagraphStyle="myPstyle3";


          I suppose the exact method depends on what you're trying to do.

          • 2. Re: applying paragraph styles
            winterm Level 5

            THANK YOU, John!

            That's exactly what I needed!

            Especially thank you for clear explanation of InsertionPoints - now I realize I had no idea how it really works... couldn't find this nowhere on the net...

            • 4. Re: applying paragraph styles
              winterm Level 5

              yeah, I know your impressive source, but it is for those one step beyond... I still must discover the very basics...