Home
> General info > QuickTip: Add Custom (CMYK/RGB/HEX) Colors to Document
QuickTip: Add Custom (CMYK/RGB/HEX) Colors to Document
Want to add custom colors to document? Wanna do it fast and painless? Here is short function that will do all job for you!
Just a brief description 🙂
Adding color to document can sometimes cause problems when we want to add color with existing name, but with this short function, you can avoid almost all possible problems while adding color. You can either just create new color, or you can even pass created color directly to object. (See usage)
First the function:
function myColorAdd(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; }
Thanks to Teus de Jong (aka Jongware) for HEX conversion thingy! 🙂
This can also be found on Adobe’s InDesign Scripting forum.
How to use:
// 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");
Directly add and assign color to object: (in this case “selected”)
// add CMYK color to document // and asign it to selected object app.selection[0].fillColor = myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
That’s it!
Fast and really handy!
Have fun! 😀
Categories: General info
InDesign CS4, InDesign CS5, Theunis de Jong
Hi Tomaxxi,
Marc did write a script you may have interest in :
http://www.indiscripts.com/post/2009/06/web-color-picker
Hey Loic!
Interesting, I never saw that 😀 Thanks!