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

Help: GREP messing up colored text

Return to Member Forum

  • Author
    Posts
    • #77389
      Henk Vrugt
      Participant

      I have this text:
      [tab] cyan [tab] yellow [tab] magenta [tab] black
      [tab] 100 [tab] 0 [tab] 0 [tab] 0
      [tab] 50 [tab] 50 [tab] 0 [tab] 40
      [tab] 0 [tab] 100 [tab] 0 [tab] 0

      the text and the according numbers are colored in the color they refer to.

      I want to change the order of colored numbers with a GREP-style to C-M-Y-K:
      find: (\w+)(\w+)(\w+)(\w+)
      change to: $1$3$2$4

      Doing so the colors get all messed up.
      Does anyone know how to fix this problem and why it happens in the first place?

    • #77893
      Peter Kahrel
      Participant

      InDesign’s formatting points to positions in the text. If you change the contents of the text, the format pointers don’t change. As a result, the text appears messed up. The way to deal with this is to change the formatting with some text tags, remove the formatting, apply your changes, and remove the tags.

      Manually this would work as follows:

      1. Find: (.+)
      Find format: cyan
      Change to: _c_$1_c_
      Change format: Black swatch

      2. Do the replacement that you had in your query.

      3. Find: _c_.+?_c_
      Find format: <nothing>
      Change to: <nothing>
      Change format: cyan swatch

      Do the above steps for magenta and yellow, using the tags _m_ and _y_, respectively.

      Finally, remove the tags:

      Find: _[cmy]_
      Change to: <nothing>
      And clear the two format fields.

      All this is captured by the script below.

      Peter

      //—————————————————————————————

      app.findGrepPreferences = app.changeGrepPreferences = null;

      changeColour (‘(.+)’, ‘_c_$1_c_’, ‘cyan’, ‘Black’);
      changeColour (‘(.+)’, ‘_m_$1_m_’, ‘magenta’, ‘Black’);
      changeColour (‘(.+)’, ‘_y_$1_y_’, ‘yellow’, ‘Black’);

      app.findGrepPreferences = app.changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = ‘t(w+)t(w+)t(w+)t(w+)’;
      app.changeGrepPreferences.changeTo = ‘t$1t$3t$2t$4’;
      app.documents[0].changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;
      changeColour (‘_c_.+?_c_’, ”, ”, ‘cyan’);
      changeColour (‘_m_.+?_m_’, ”, ”, ‘magenta’);
      changeColour (‘_y_.+?_y_’, ”, ”, ‘yellow’);

      app.findGrepPreferences = app.changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = ‘_[cmy]_’;
      app.changeGrepPreferences.changeTo = ”;
      app.documents[0].changeGrep();

      function changeColour (f, r, c1, c2) {
      app.findGrepPreferences.findWhat = f;
      app.changeGrepPreferences.changeTo = r;
      app.findGrepPreferences.fillColor = c1;
      app.changeGrepPreferences.fillColor = c2;
      app.documents[0].changeGrep();
      }

      //—————————————————————————————

    • #77945
      Henk Vrugt
      Participant

      Thanks Peter.

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