Mobile app version of vmapp.org
Login or Join
Dunderdale640

: InDesign script to alternate text color every other line in a text box I have a very long list of names that I need to alternate the CMYK color value every other line. I found this script

@Dunderdale640

Posted in: #AdobeIndesign #IndesignScripting

I have a very long list of names that I need to alternate the CMYK color value every other line.

I found this script online that changes the tint every 3rd line:

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

}


I tried changing the script to change the CMYK value doing this:

var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
p = app.selection[0].lines[i];
if (i%2 === 1) { p.colorValue=[0,100,100,0]; }

}


But using "colorValue" is not supported. How can I change the script to make every other line in a text box change the color value?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Dunderdale640

3 Comments

Sorted by latest first Latest Oldest Best

 

@Ann6370331

I suggest this version
Kudos to indisnip.wordpress.com

// found on bit.ly/h5EobK indisnip.wordpress.com ->
// how to apply:
//
// add CMYK color
// myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
//
// add RGB color
// myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [33,66,99]);
//
// add HEX color
// myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, "ABCDEF");
//
// add color directly
// add CMYK col or to document
// and assign it to selected object
//app.selection [0].fillColor = myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
color_maker = function(myDocument, myColorName, myColorModel, myColorValue) {
if (myColorValue instanceof Array === false) {
myColorValue = [(parseInt(myColorValue, 16) >> 16) & 0xff, (parseInt(myColorValue, 16) >> 8) & 0xff, parseInt(myColorValue, 16) & 0xff];
myColorSpace = ColorSpace.RGB;
} else {
if (myColorValue.length == 3)
myColorSpace = ColorSpace.RGB;
else
myColorSpace = ColorSpace.CMYK;
}
try {
myColor = myDocument.colors.item(myColorName);
myName = myColor.name;
} catch (myError) {
myColor = myDocument.colors.add();
myColor.properties = {
name: myColorName,
model: myColorModel,
space: myColorSpace,
colorValue: myColorValue
};
}
return myColor;
};
var main = function() {
if (app.documents.length === 0) return;
var doc = app.activeDocument;
if (doc.selection.length === 0) return;
var sel = app.activeDocument.selection[0];
for (var i = 0; i < sel.lines.length; i++) {
if (i % 2 === 0) {
var col = color_maker(doc, 'my color ' + i, ColorModel.PROCESS, [0, 0, 0, Math.random() * 100]);
sel.lines[i].fillColor = col;
}
}
};
main();

10% popularity Vote Up Vote Down


 

@Jamie315

How about:

for ( var i=0; i < app.selection[0].paragraphs.length; i++ ) {

var p = app.selection[0].lines[i],
even = i % 2 === 1;

if ( even ) {

p.fillColor = "My Swatch Name";

// Or one of these two:
// p.applyParagraphStyle( app.activeDocument.paragraphStyles.itemByName("My Paragraph Style"), true );
// p.applyCharacterStyle( app.activeDocument.characterStyles.itemByName("My Character Style"), false );

}

}

10% popularity Vote Up Vote Down


 

@Karen819

Credit to Kasyan Servetsky for creating the script.

var i, p, color;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
p = app.selection[0].lines[i];
color = makeColor("C=0 M=100 Y=100 K=0", ColorSpace.CMYK, ColorModel.process, [0, 100, 100, 0]);
if (i%2 === 1) {
p.fillColor = color;
}
}

function makeColor(colorName, colorSpace, colorModel, colorValue) {
var doc = app.activeDocument;
var color = doc.colors.item(colorName);
if (!color.isValid) {
color = doc.colors.add({name: colorName, space: colorSpace, model: colorModel, colorValue: colorValue});
}
return color;
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme