Our site is under maintenance and some features may not work as expected.

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 or GREP formatting to apply alternating character colors

Return to Member Forum

  • Author
    Posts
    • #61863
      Anonymous
      Inactive

      I have a unique problem where I need to apply multiple character colors that alternate on header text.

      A client's design standards call for the headers to alternate between 4 colors on each character. For example, the header “LOREM IPSUM” would have the L color 1, O color 2, R color 3, E color 4, M color 1, (ignore the space if possible), I color 2, and so on. This would repeat for all the characters in the header text.

      I haven't been able to figure out a GREP, but I assume I would make a character style for each color. Or maybe this needs to be a script?

      Thanks for any ideas.

    • #61865

      Since you can only apply one color (or char style) at a time using GREP, I think a script would work better.

      Let me think one while typing (uh, that means I am making it up as I write). Watch out for niceties added by the forum software, such as en-dashes and curly quotes. Those do not belong to the script!

      .. wait .. On 2nd thought, it'd probably be better if I fire up the ol' Mac for this as I was going to attempt to make up and type in an InDesign script on my iPad ;)

    • #61866

      Here is a Javascript for you. Change the swatch names in the first line to the ones you are using, then select some text and run the script. Enjoy:

      var colorlist = [ “red”, “orange”, “yellow”, yellow-white ];
      var p = 0;
      for (i=0; i<app.selection[0].characters.length; i++)
      {
      if (app.selection[0].characters[i].contents != ' ')
      app.selection[0].characters[i].fillColor = colorlist[(p++) & 3];
      }

      By the way, this is what it looks like when run with 4 shades of red/yellow:

    • #61874
      Anonymous
      Inactive

      Fantastic! Thanks so much. This is going to save me a lot of time!

    • #61915
      Marc Autret
      Member

      Jongware said:

      Since you can only apply one color (or char style) at a time using GREP (…)


      This is not quite true. In fact, alternating colors can be done through GREP styles, as demonstrated here:

      https://www.indiscripts.com/pos&#8230;..rep-styles

      Hope that helps.

      @+

      Marc

    • #61916

      Marc, you are a sly devil ;)

      But can you make it ignore the space if possible as well?

    • #61917
      Marc Autret
      Member

      Jongware said:

      Marc, you are a sly devil ;)

      But can you make it ignore the space if possible as well?


      OK, you win ;-)

      However, I'm quite sure it would be possible to deal with spaces by refining the GREP rules, but I confess I have not the courage to try…

      @+

      Marc

    • #61950
      Anonymous
      Inactive

      Hmmm why not do it with a Nested Style???

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