4 Replies Latest reply on Jan 1, 2013 12:16 PM by claudius X

    Adding style to next paragraph

    claudius X Level 1

      Can someone help? I have a problem - long (300+ pages) text with questions and answers. Questions are using paragraph style "x" and answers are using paragraph style "y". There are usually 3-6 paragraphs of text in every answer. I need to change only the first paragraph's style after the question paragraph to style "z", so that the structure of styles would look like  x-z-y-y-y-y-x-z-y-y... (now it looks x-y-y-y-y-y-x-y-y-y...). Can it be done using scripting?

      InDesign CS6 Win 7 64-bit

      Claudius

        • 1. Re: Adding style to next paragraph
          Jump_Over Level 5

          Hi,

           

          assumed your story (text box) is selected before script run:

           

           

          ...........

          myDoc = app.activeDocument;

          myStory = app.selection[0].parentStory;

          myQuestion = myDoc.paragraphStyles.item("x");     // edit the name ("x") if required

          my1stAnswer = myDoc.paragraphStyles.item("z");     // edit the name ("z") if required

          for (var k = 0; k < myStory.paragraphs.length; k++)

               if (myStory.paragraphs[k].appliedParagraphStyle == myQuestion)

               myStory.paragraphs.nextItem(myStory.paragraphs[k]).appliedParagraphStyle = my1stAnswer;

          ..........

           

          enjoy,

          • 2. Re: Adding style to next paragraph
            claudius X Level 1

            Thank you,

            it works. But InDesign CS6 for some reason freezes before the end... If I restart it I see almost every change completed. There are about 20something pages not styles changed at the end... Every time different number of pages. So there is no obvious reason for that as long as I see except op.sys or InDesign untability...

            Claudius

            • 3. Re: Adding style to next paragraph
              Jump_Over Level 5

              Hi,

              try with some modification in the last line:

              ...

              myStory.paragraphs[k+1].appliedParagraphStyle = my1stAnswer;

              ...

               

              Thats because .nextItem() could consume a lot of memory with big stories

              rgds

              • 4. Re: Adding style to next paragraph
                claudius X Level 1

                That did the trick! Now it takes only about 20 sec for 300+ pages with approx 3-5 changes per page.

                Thanx! Claudius