Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to swap around the order of certain paragraph styles?

Return to Member Forum

  • Author
    Posts
    • #92906
      Anonymous
      Inactive

      Could a script be written to swap the order of two consecutive paragraph styles around? A GREP search and replace, somehow?

      I need the headings to be in this order:

      Name of concert venue
      Date and location of concert
      Name of musician

      But it’s been sent in this order:

      Date and location of concert
      Name of concert venue
      Name of musician

      There are thousands of entries. I was able to apply separate paragraph styles to these headings (thankfully, all those headings had certain peculiarities and things in common that meant I could apply styles to them using a search and replace).
      But they are still in the wrong order. So… could a script identify instances of Paragraph Style 2 followed by Paragraph Style 1 and move those paragraphs around, to be Paragraph 1 followed by Paragraph 2?

      It did occur to me that I could alter the Baseline Shift in those Paragraph Styles , so even though they’d still technically be in the wrong order, in practice on the page they’d look right. I suspect my boss wouldn’t like it though as a matter of principle.

    • #92907
      Masood Ahmad
      Participant

      Hi Matt,

      It would be more convenient if you could supply the peculiarities for each of those two paragraph. That can then be used in the GREP search.

      However, if the lines begin with Name and Date as text, then you can use the below code to find and change and then swap it around.

      GREP Find/Change:
      Find What:(^Date.+)\r(^Name.+)
      Change to::$2\r$1

      Hope you got some idea!

    • #92909
      Anonymous
      Inactive

      Thanks.

      Here’s two specific examples:

      23 September 2008, Eugene, Oregon, USA
      John Henry’s
      Jessica MacMillan

      26 September 2008, Vancouver, CAN
      Media Club
      Samantha Roberts

      I need them to be:

      John Henry’s
      23 September 2008, Eugene, Oregon, USA
      Jessica MacMillan

      Media Club
      26 September 2008, Vancouver, CAN
      Samantha Roberts

    • #92910
      Masood Ahmad
      Participant

      Try this:

      GREP Find/Change:
      Find What:(^\d{1,2}.+)\r(^[\u].+)
      Change to::$2\r$1

    • #92911
      Anonymous
      Inactive

      Thanks – that works beautifully! I really need to get to grips with my GREP!

    • #92914
      Masood Ahmad
      Participant

      That’s great.

      You can start your GREP journey here at IS: https://creativepro.com/resources/grep

      Apart from this, there are many members who voluntarily share their experiences and are ready to provide any possible combinations of code here at InDesign Secrets. Please feel free to raise your queries…

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
Forum Ads