• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Looking for a automated way to alternate text color in a list

New Here ,
Jul 22, 2011 Jul 22, 2011

Copy link to clipboard

Copied

I have a long list of names and I'm looking for an automated way to color them.

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

Got close with converting the text into a table, but I can only get cell fills or cell strokes to alternate.

I couldn't figure out a way to control the text stroke and fill.

Grep? Tables? External script?

Any and all answers are greatly appreciated,

Thanks again

TOPICS
Scripting

Views

3.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jul 24, 2011 Jul 24, 2011

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

I'm not sure I understand the sequence of colours as you've described it, but if you just want to cycle between three colours, such as:

100k

50k

30k

100k

50k

30k

100k

etc.

then you could set up a paragraph style for each colour.  After all three styles are created, go back to edit each style and change the "Next Style" (in the General tab) to the next style in the sequence.

To apply to the text: select all the text then righ

...

Votes

Translate

Translate
LEGEND ,
Jul 22, 2011 Jul 22, 2011

Copy link to clipboard

Copied

A short easy script:

var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
  p = app.selection[0].paragraphs;
  if (i%3 === 2) { p.fillTint = 50; }
  if (i%2 === 1) { p.fillTint = 30; }
}

Though what's supposed to happen every six, when the 2nd and the 3rd line up, I'm not sure.

This assumes one paragraph per line. I suppose you could replace .paragraphs with .lines if you wanted.

Oh, this operates on the selected textframe. So select a text frame first. (Well, or anything with paragraphs/lines I guess).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2011 Jul 23, 2011

Copy link to clipboard

Copied

Thanks John !

-Stupid Question:  where do I paste the script ?

I mean is there a place in indesign for code ? or is this an external script ?

I'm on a a mac, if that matters.

-If I wanted just every second line to tint, I'm assuming it would be

var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
  p = app.selection[0].lines;
  if (i%3 === 2) { p.fillTint = 50; }
 
}
Thanks again for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2011 Jul 23, 2011

Copy link to clipboard

Copied

Save it as alternateText.jsx (or whatever you like) in your favorite text editor (e.g. TextEdit) and then follow the instructions at http://www.danrodney.com/scripts/directions-installingscripts.html.

-If I wanted just every second line to tint, I'm assuming it would be

Not quite, that would do every 3rd line:

  if (i%3 === 2) { p.fillTint = 50; } }

"i%3" is an expressioin that returns the remainder of i divided by 3. i is the line count. So for the first line, i is 0 and i%3 is 0. Second line i is 1 and i%3 is 1. Third line: i is 2 and i%3 is 2. Fouth line: i is 3 and i%3 is 0. Fifth line: i is 4 and i%3 is 1. etc. etc.

So for every second line, use i%2. You can say "i%2===1" if you want every other line starting with the 2nd line. Or "i%2===0" if you want every other line starting with the first line.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2011 Jul 23, 2011

Copy link to clipboard

Copied

You are awesome.

I will try this and report back !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 24, 2011 Jul 24, 2011

Copy link to clipboard

Copied

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

I'm not sure I understand the sequence of colours as you've described it, but if you just want to cycle between three colours, such as:

100k

50k

30k

100k

50k

30k

100k

etc.

then you could set up a paragraph style for each colour.  After all three styles are created, go back to edit each style and change the "Next Style" (in the General tab) to the next style in the sequence.

To apply to the text: select all the text then right click on the 100k style in the Paragraph Styles pallet and choose "Apply "100k" then Next Style".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2011 Jul 24, 2011

Copy link to clipboard

Copied

Oh, yes, that way works too. Sometimes it's easy to put on one's scripting blinders when the question gets asked in the scripting forum.

Of course, if you truly want every-other and every-third, then you need six styles with Next Styles, which can get a little tricksy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 27, 2011 Jul 27, 2011

Copy link to clipboard

Copied

Sorry for being MIA, just got back to working on this thing.. your idea works perfect!

well done, I'm sure the script would have worked just as well- but this is super easy

Fantastish and thanks much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 27, 2011 Jul 27, 2011

Copy link to clipboard

Copied

Oh I just realized, that when ever I change the sqeuence of the names, they now change colours, because of their paragraph

deignation (obviously eh?) the strange thing is if I do a automatic find/change command such as change all P to SPACE

they change back to the first style, but if I manualy delete the paragraph with back space they stay with their "Next Style".

Is there a way to lock them into their current paragraph style, so that even If I move them around they stay with their current

settings ?

If this is not clear let me know i'll try and clarify.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 27, 2011 Jul 27, 2011

Copy link to clipboard

Copied

LATEST

When moving a name, make sure you select the entire paragraph including the invisible paragraph symbol at the end (Type > Show Hidden Characters). Otherwise you may end up pasting text with one paragraph style into a paragraph with a different style and creating a style override (this will show in the Paragraph Styles pallet with a + sign next to the name).

If a paragraph has overrides you can clear them by option (alt) clicking on the name of the style in the Paragraph Styles pallet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines