Copy link to clipboard
Copied
There is a way to generate an *.ASE file for importing color samples into Adobe software (PS, AI, ID...) starting from a list I have in a TXT, CSV, EXCEL or other file.
example of the list:
#e0cffc
#c29ffa
#a370f7
#8540f5
#6610f2
#520dc2
#3d0a91
#290661
#140330
therefore I would like these color codes to be saved in an *.ASE file that can be imported into INDESIGN which generates the 9 colors (9 as 10,000 colors)
Step 2 (optional) - if these colors can somehow be "also" converted from HEX to CMYK
1 Correct answer
Hi @Nicky G. This script will make a new document with RGB swatches from a hex list saved as a .txt file on your desktop—it expects just the hex value (no # prefix) in this format:
e0cffc
c29ffa
a370f7
8540f5
The swatches get saved in a color group named sRGB HEX, and from there you can save an .ASE file from the Swatches panel
var hc = readFile("~/Desktop/HexColors.txt")
//an array of hex values (no # prefix)
var hexList = hc.split("\n")
//a new document with sRGB as its assigned
...
Copy link to clipboard
Copied
Hi @Nicky G. This script will make a new document with RGB swatches from a hex list saved as a .txt file on your desktop—it expects just the hex value (no # prefix) in this format:
e0cffc
c29ffa
a370f7
8540f5
The swatches get saved in a color group named sRGB HEX, and from there you can save an .ASE file from the Swatches panel
var hc = readFile("~/Desktop/HexColors.txt")
//an array of hex values (no # prefix)
var hexList = hc.split("\n")
//a new document with sRGB as its assigned RGB profile
var d = app.documents.add();
app.activeDocument.rgbProfile="sRGB IEC61966-2.1"
//remove default swatches
var us = d.unusedSwatches
for (var i = 0; i < us.length; i++){
us[i].remove()
};
//make a new color group named HEX
var cg = makeColorGroup(d, "sRGB HEX")
//create RGB swatches with HEX names from the hexList array
var ns;
for (var i = 0; i < hexList.length; i++){
ns = makeSwatch(d, hexList[i], cg)
ns.properties = {model:ColorModel.PROCESS, space:ColorSpace.RGB, colorValue:hexToRgb(hexList[i])}
};
/**
* Gets the RGB values as an array from the provided hex value
* @ param the hex value
* @ return array of RGB values
*/
function hexToRgb(hx) {
var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hx);
var a = [];
var i = 3;
while (i--) a.unshift(parseInt(r[i+1], 16));
return a
}
/**
* Makes a new named Swatch
* @ param d document
* @ param color name
* @ param group name
* @ return the new swatch
*/
function makeSwatch(d, n, cg){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n, parentColorGroup:cg});
}
}
/**
* Makes a new color group
* @ param d document
* @ param n group name
* @ return the new group
*
*/
function makeColorGroup(d, n){
if (d.colorGroups.itemByName(n).isValid) {
return d.colorGroups.itemByName(n);
} else {
return d.colorGroups.add({name:n});
}
}
/**
* Read a text file
* @ param p the path to the text file
* @ return the file‘s text
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x; //returns the text in the file sampletext.txt
}
After running:
Also, HEX is an RGB notation, so there isn’t a CMYK equivalent. You can convert RGB Hex colors to CMYK, but the resulting values depend on the source RGB profile and the destination CMYK profile which could be anything.
You can convert HEX values to CMYK on an Export to PDF by setting a Output tab’s Destination to a CMYK profile, which will color manage the conversion into the chosen CMYK space during the export.
Copy link to clipboard
Copied
Great Script, does what I'm looking for Thanks!
Only if possible make improvements:
1. The script creates a New document to insert the RGB/HEX color swatches - I noticed that the script inserts the colors in RGB, but it creates a CMYK document - preset for Printing. (should be WEB preset RGB)
2. you can read the source file with colors in this format:
Color_Name: #Hex
Navy Blue: 171547
- For a visual logic too, writing the data source like this would be correct: Blue Navy: #171547
if it would be possible (eliminate the hash # when composing the color tables)
then split the name and the Hex into two lists, where the color code will generate the color and the Name will appear in the color list in the panel?
3. RGB to CMYK color conversion is done directly from the ID swatches panel. But for a correct conversion the working space of the source document must be WEB RGB
Copy link to clipboard
Copied
but it creates a CMYK document - preset for Printing. (should be WEB preset RGB)
InDesign doesn’t have a document color mode, a page can have a mix of RGB, CMYK, and Lab colors and objects. The Document Setup lets you choose an Intent but all that does is set the initial defaults—you can still create a mix of RGB, CMYK or Lab defined swatches in any document. The hex colors the script is generating are all RGB, so the Intent doesn’t matter. When you Save the sRGB HEX group as an .ASE file, the swatches will be saved as RGB. When you Load the .ase file, the appearance of the loaded RGB Swatches is going to depend on the loading document’s assigned RGB profile.
RGB to CMYK color conversion is done directly from the ID swatches panel. But for a correct conversion the working space of the source document must be WEB RGB
If you convert the sRGB values to CMYK from the Swatches panel, the Color Settings’ Working Spaces are not used—it is the document’s assigned profiles that make the conversion from RGB to CMYK. Check Edit>Assign Profiles to set the source RGB profile and the destination CMYK profile (not Color Settings). Web browsers use sRGB as the RGB space for HTML hex coded values.
In this example the conversion of the selected swatches would be from sRGB to Coated FOGRA39 (not from the current Color Settings AdobeRGB and Coated GRACoL 2006 Working Spaces). If you choose a different CMYK assignment you will get different CMYK values. Also the Solid Color Intent you choose can have some affect the converted CMYK values.
Copy link to clipboard
Copied
OK Thanks.
for point number 2 is it possible to do nothing?
Copy link to clipboard
Copied
Try this where your text file lines are setup as the color name tab hex value:
var hc = readFile("~/Desktop/HexColors.txt")
//text file format color name tab color value no #
/*
Color Name e0cffc
Color Name c29ffa
Color Name a370f7
Color Name 8540f5
Color Name 6610f2
Color Name 520dc2
Color Name 3d0a91
Color Name 290661
Color Name 140330
*/
//an array of hex values (no # prefix)
var hexList = hc.split("\n")
//a new document with sRGB as its assigned RGB profile
var d = app.documents.add();
app.activeDocument.rgbProfile="sRGB IEC61966-2.1"
//remove default swatches
var us = d.unusedSwatches
for (var i = 0; i < us.length; i++){
us[i].remove()
};
//make a new color group named HEX
var cg = makeColorGroup(d, "sRGB HEX")
//create RGB swatches with HEX names from the hexList array
var ns, ha, cn;
for (var i = 0; i < hexList.length; i++){
ha = hexList[i].split("\t")
cn = ha[0] + " #" + ha[1]
//$.writeln(cn)
ns = makeSwatch(d, cn, cg)
ns.properties = {model:ColorModel.PROCESS, space:ColorSpace.RGB, colorValue:hexToRgb(ha[1])}
};
/**
* Gets the RGB values as an array from the provided hex value
* @ param the hex value
* @ return array of RGB values
*/
function hexToRgb(hx) {
var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hx);
var a = [];
var i = 3;
while (i--) a.unshift(parseInt(r[i+1], 16));
return a
}
/**
* Makes a new named Swatch
* @ param d document
* @ param color name
* @ param group name
* @ return the new swatch
*/
function makeSwatch(d, n, cg){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n, parentColorGroup:cg});
}
}
/**
* Makes a new color group
* @ param d document
* @ param n group name
* @ return the new group
*
*/
function makeColorGroup(d, n){
if (d.colorGroups.itemByName(n).isValid) {
return d.colorGroups.itemByName(n);
} else {
return d.colorGroups.add({name:n});
}
}
/**
* Read a text file
* @ param p the path to the text file
* @ return the file‘s text
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x; //returns the text in the file sampletext.txt
}
Copy link to clipboard
Copied
Perfect!!!
if I insert the hash # in the txt list it works the same. The color code is generated well.
Thanks Infinite
Color Name #e0cffc
Copy link to clipboard
Copied
Also the link below might be useful when you are thinking about assigning a set CMYK value to a hex RGB color. You only want to do it when the print destination is known, otherwise you will get CMYK-to-CMYK conversions or appearance problems at output.
All of your example colors are outside of a typical CMYK gamut and are not printable.
https://community.adobe.com/t5/indesign-discussions/branding-color-guide/td-p/10818696
Copy link to clipboard
Copied
I have to study this a bit and understand it!
Copy link to clipboard
Copied
sorry for the inconvenience...
Could this script be adapted for RGB and CMYK data sources?
colorname RGB 24 154 149
{and}
colorname CMYK 24 100 56 12
-----
Using as default color profiles in adobe (AdobeRGB 1998)
do you think it would be better to put in:
app.activeDocument.rgbProfile="sRGB IEC61966-2.1"
the profile
app.activeDocument.rgbProfile="Adobe RGB (1998)"
to make sure that if I detect a color change from HEX to CMYK in the PHOTOSHOP color panel it gives me the same conversion values that I get from the Indesign script?
Or is it tasteful to keep sRGB 1966-2.1?
Copy link to clipboard
Copied
If you change the for loop to this the colors will be named using the hex value’s RGB exivalent:
//create RGB swatches with RGB names from the hexList array
var ns, ha, cn;
for (var i = 0; i < hexList.length; i++){
ha = hexList[i].split("\t")
cn = ha[0] + " #" + ha[1]
ns = makeSwatch(d, cn, cg)
ns.properties = {model:ColorModel.PROCESS, space:ColorSpace.RGB, colorValue:hexToRgb(ha[1])}
ns.name = ha[0] + " " + ns.colorValue[0] + " " + ns.colorValue[1] + " " + ns.colorValue[2]
};
Using as default color profiles in adobe (AdobeRGB 1998) do you think it would be better to put in:
app.activeDocument.rgbProfile="sRGB IEC61966-2.1"
I was assuming the usage for the hex values was for getting web HTML values. If you change the profile to something other than sRGB the appearance of the hex colors is going to change:
sRGB
Adobe RGB
ProPhoto RGB
All of these colors are significantly out-of-gamut so a conversion to any CMYK space will change the appearance:
Copy link to clipboard
Copied
OK for color profile.
Maybe I misunderstood point number 1.
The script you sent me to replace,
"//create RGB swatches with RGB names from the hexList array"
It does nothing but insert the RGB Nomenclature in the name of the color swatch. It always starts from a HEX data source and creates an RGB color sample with the nomenclature COLOR NAME 125 145 145 (RGB value).
I simply asked to be able to generate the list of color samples starting from a data source expressed with the RGB color triad instead of the hexadecimal
color_name RGB 24 154 149
ditto I was asking the same thing for a data source expressed in CMYK
color_name CMYK 24 15 80 5
Copy link to clipboard
Copied
For RGB (value numbers need to separated by commas)
var hc = readFile("~/Desktop/HexColors.txt")
//text file format color name tab color value string
/*
Color Name 120,120,120
Color Name 220,120,120
Color Name 120,120,220
*/
//the color list’s lines
var cList = hc.split("\n")
var d = app.documents.add();
//remove default swatches
var us = d.unusedSwatches
for (var i = 0; i < us.length; i++){
us[i].remove()
};
//make a new color group named HEX
var cg = makeColorGroup(d, "sRGB")
//create RGB swatches with RGB names from the hexList array
var ns, ha, cn, cv;
for (var i = 0; i < cList.length; i++){
ha = cList[i].split("\t")
cn = ha[0] + " " + ha[1]
cv = ha[1].split(",")
for (var j = 0; j < cv.length; j++){
cv[j] = Number(cv[j])
};
ns = makeSwatch(d, cn, cg)
ns.properties = {model:ColorModel.PROCESS, space:ColorSpace.RGB, colorValue:cv};
};
/**
* Makes a new named Swatch
* @ param d document
* @ param color name
* @ param group name
* @ return the new swatch
*/
function makeSwatch(d, n, cg){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n, parentColorGroup:cg});
}
}
/**
* Makes a new color group
* @ param d document
* @ param n group name
* @ return the new group
*
*/
function makeColorGroup(d, n){
if (d.colorGroups.itemByName(n).isValid) {
return d.colorGroups.itemByName(n);
} else {
return d.colorGroups.add({name:n});
}
}
/**
* Read a text file
* @ param p the path to the text file
* @ return the file‘s text
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x; //returns the text in the file sampletext.txt
}
CMYK
var hc = readFile("~/Desktop/HexColors.txt")
//text file format color name tab color value string
/*
Color Name 20,20,20,0
Color Name 80,20,20,0
Color Name 20,90,0,0
*/
var cList = hc.split("\n")
var d = app.documents.add();
//remove default swatches
var us = d.unusedSwatches
for (var i = 0; i < us.length; i++){
us[i].remove()
};
//make a new color group named CMYK
var cg = makeColorGroup(d, "CMYK")
//create CMYK swatches with CMYK names from the hexList array
var ns, ha, cn, cv;
for (var i = 0; i < cList.length; i++){
ha = cList[i].split("\t")
cn = ha[0] + " " + ha[1]
cv = ha[1].split(",")
for (var j = 0; j < cv.length; j++){
cv[j] = Number(cv[j])
};
ns = makeSwatch(d, cn, cg)
ns.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:cv};
};
/**
* Makes a new named Swatch
* @ param d document
* @ param color name
* @ param group name
* @ return the new swatch
*/
function makeSwatch(d, n, cg){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n, parentColorGroup:cg});
}
}
/**
* Makes a new color group
* @ param d document
* @ param n group name
* @ return the new group
*
*/
function makeColorGroup(d, n){
if (d.colorGroups.itemByName(n).isValid) {
return d.colorGroups.itemByName(n);
} else {
return d.colorGroups.add({name:n});
}
}
/**
* Read a text file
* @ param p the path to the text file
* @ return the file‘s text
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x; //returns the text in the file sampletext.txt
}

