Copy link to clipboard
Copied
Hello,
I need to code a script to do the same thing as its done with the Swatch Options Name With Colour Value check option.
1 Correct answer
Hi @Amine9 , I don’t think there is a built-in method that will name a swatch with its color value, so you would have to write a function. Try this:
var s = app.activeDocument.swatches
for (var i = 0; i < s.length; i++){
try {
setNameAsValue(s[i])
}catch(e) {}
};
/**
* Sets the swatch name to color values
* @ param the swatch
* @ return void
*
*/
function setNameAsValue(s){
var va = s.colorValue;
var ns;
if (s.space == ColorSpace.CMYK) {
ns = "C=
...
Copy link to clipboard
Copied
Hi @Amine9 , I don’t think there is a built-in method that will name a swatch with its color value, so you would have to write a function. Try this:
var s = app.activeDocument.swatches
for (var i = 0; i < s.length; i++){
try {
setNameAsValue(s[i])
}catch(e) {}
};
/**
* Sets the swatch name to color values
* @ param the swatch
* @ return void
*
*/
function setNameAsValue(s){
var va = s.colorValue;
var ns;
if (s.space == ColorSpace.CMYK) {
ns = "C=" + Math.round(va[0]) + " M=" + Math.round(va[1]) + " Y=" +Math.round(va[2]) + " K=" + Math.round(va[3])
}
if (s.space == ColorSpace.RGB) {
ns = "R=" + Math.round(va[0]) + " G=" + Math.round(va[1]) + " B=" +Math.round(va[2])
}
if (s.space == ColorSpace.LAB) {
ns = "L=" + Math.round(va[0]) + " A=" + Math.round(va[1]) + " B=" +Math.round(va[2])
}
if (s.space == ColorSpace.HSB) {
ns = "H=" + Math.round(va[0]) + " S=" + Math.round(va[1]) + " B=" +Math.round(va[2])
}
s.name = ns
}
Copy link to clipboard
Copied
I'm trying to emulate the checkbox because some swatches are 'damaged' when I get their space colour its the unused value, but when I use the checkbox => the swatch name will contain the colour and I can get the good colour value from there.
Copy link to clipboard
Copied
Check out this script.

