Last active
August 29, 2015 14:03
-
-
Save jdforsythe/1aa8d31f77979bf44655 to your computer and use it in GitHub Desktop.
InDesign: Add color to document function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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