Cycling through paragraph styles script – Help Needed

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Cycling through paragraph styles script – Help Needed

Tagged: ,

Viewing 2 reply threads
  • Author
    Posts
    • #76584
      David Nightingale
      Participant

      Hi

      I have a large document (potentially 3000 pages), on each page is a graphic of a picture frame and inside each frame is a famous quotation. I need to have the type in each quotation set in a different font so i’ve setup 10 different paragraph styles. I need a script that will apply ‘QuoteStyle1’ to the text on the first page, ‘QuoteStyle2’ to the next page etc, and once ‘QuoteStyle10’ has been applied the script loops and continues to cycle through the styles applying a different style on each page until it reaches the end of the document.

      I’ve made a start on the script but I think the problem is line 11 – I want to run the script without having to select anything.

      Here’s the script i’ve got so far:

      paraStyleList = [ “QuoteStyle1”, “QuoteStyle2”, “QuoteStyle3”, “QuoteStyle4”, “QuoteStyle5”, “QuoteStyle6”, “QuoteStyle7”, “QuoteStyle8”, “QuoteStyle9”, “QuoteStyle10” ];
      skipStyle1 = app.activeDocument.paragraphStyles.item(“VisibleName”);
      skipStyle2 = app.activeDocument.paragraphStyles.item(“ColourPink”);
      skipStyle3 = app.activeDocument.paragraphStyles.item(“ColourYellow”);
      skipStyle4 = app.activeDocument.paragraphStyles.item(“ColourGreen”);
      skipStyle5 = app.activeDocument.paragraphStyles.item(“ColourBlue”);
      skipStyle6 = app.activeDocument.paragraphStyles.item(“ColourRed”);
      skipStyle7 = app.activeDocument.paragraphStyles.item(“ColourPurple”);
      skipStyle8 = app.activeDocument.paragraphStyles.item(“ColourOrange”);

      story = app.selection[0].parentStory;

      currentPStyle = 0;
      for (i=0; i<story.paragraphs.length; i++)
      {
      if (i > 0 && story.paragraphs[i].contents.match(/[\l\u]/))
      {
      currentPStyle = currentPStyle+1;
      if (currentPStyle == paraStyleList.length) currentPStyle = 0;
      }
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle1)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle2)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle3)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle4)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle5)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle6)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle7)
      if (story.paragraphs[i].appliedParagraphStyle != skipStyle8)
      {
      story.paragraphs[i].appliedParagraphStyle = paraStyleList[currentPStyle];
      }
      }

      Some further info that may or may not be of use – All of the quotes are being pulled in from a data-merge. There’s also a name and a colour coming from the data-merge. The background on each picture frame is a different colour and that is created with the a very large ‘Rule Below’ in a number of other paragraph styles. These are being applied with a ‘Find&ReplacebyList’ i.e. find ‘Red’ replace with paragraph style ‘ColourRed’. In the script i’ve tried to skip these ‘Colour’ paragraph styles (lines 2-9) so it’s only the ‘Quote’ styles that the script effects.

      Any help getting this running would be most helpful.

    • #76615

      Regarding the selection: if this story thread is the only one spanning multiple frames, you can loop over your stories and select the one that has a ‘next’ frame:

      for (i=0; i < app.activeDocument.stories.length; i++)
      {
        if (app.activeDocument.stories[i].textContainers.length > 2)
        {
           story = app.activeDocument.stories[i];
           break;
        }
      }

      If necessary, you can only check the ones that start on your first page:

      for (i=0; i < app.activeDocument.pages[0].textFrames.length; i++)
        if (app.activeDocument.pages[0].textFrames[i].nextTextFrame &&
          app.activeDocument.pages[0].textFrames[i].parentStory.textContainers.length > 2)
        {
          story = app.activeDocument.pages[0].textFrames[i].parentStory;
          break;
        }

      … if that fails as well (if you have multiple independent text threads), maybe you could search for a paragraph style that is unique to the story you need.

      (For the record, I did not test it but the rest of your script looks fine.)

    • #76616
      David Nightingale
      Participant

      Hi

      Thanks for getting back. Just to update this thread I got the script working with help from the Adobe forum yesterday, anybody interested can see it here https://forums.adobe.com/thread/1900288

      Thanks again

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
>