Skip to content

Instantly share code, notes, and snippets.

@jdforsythe
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdforsythe/1aa8d31f77979bf44655 to your computer and use it in GitHub Desktop.
Save jdforsythe/1aa8d31f77979bf44655 to your computer and use it in GitHub Desktop.
InDesign: Add color to document function
function addColor(doc, colorName, colorModel, colorValue){
if (colorValue instanceof Array == false) {
colorValue = [(parseInt(colorValue, 16) >> 16 ) & 0xff, (parseInt(colorValue, 16) >> 8 ) & 0xff, parseInt(colorValue, 16 ) & 0xff ];
colorSpace = ColorSpace.RGB;
}
else {
if(colorValue.length == 3)
colorSpace = ColorSpace.RGB;
else
colorSpace = ColorSpace.CMYK;
}
try {
newColor = myDocument.colors.item(colorName);
newName = newColor.name;
}
catch (err) {
newColor = doc.colors.add();
newColor.properties = {name:colorName, model:colorModel, space:colorSpace, colorValue:colorValue};
}
return newColor;
}
// add CMYK color
addColor(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
// add RGB color
addColor(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [33,66,99]);
// add HEX color
addColor(app.activeDocument, "My Custom Color", ColorModel.PROCESS, "FF00FF");
// add CMYK color to document
// and asign it to selected object
app.selection[0].fillColor = addColor(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment