Copy link to clipboard
Copied
I am using the script below to extract RGB values in an Ai document using the ASE swatch color and placing each R G B value in a separate column inside a CVS Excel sheet. I want to assign the names of the swatches to the swatche's RGB values instead of the sequenced numbering [Column A = I.D.] that is currectly in the script but I don't know how to do this.
var listfile = "/Users/Name/Desktop/Name.csv"; //add Filename
var doc = activeDocument;
var col = doc.swatches;
var info = new Array();
if(doc.documentColorSpace == DocumentColorSpace.CMYK)
{
info.push("I.D.,C,M,Y,K");
for(var i = 0; i < col.length;i++)
{
if(col[i].color=="[CMYKColor]")
{
var c = Math.round(col[i].color.cyan);
var m = Math.round(col[i].color.magenta);
var y = Math.round(col[i].color.yellow);
var k = Math.round(col[i].color.black);
info.push(i+","+c+","+m+","+y+","+k);
} else {info.push(i);}
}
}
if(doc.documentColorSpace == DocumentColorSpace.RGB)
{
info.push("I.D.,R,G,B");
for(var i = 0; i < col.length;i++)
{
if(col[i].color=="[RGBColor]")
{
var r = Math.round(col[i].color.red);
var g = Math.round(col[i].color.green);
var b = Math.round(col[i].color.blue);
info.push(i+","+r+","+g+","+b);
} else {info.push(i);}
}
}
var thefile = new File(listfile); //pass the file to a Variable
var isopen = thefile.open("w"); //open file for editing
if (isopen)//test file is open
{
thefile.seek(0,0);
for(var j = 0; j < info.length; j++)
{
thefile.writeln(info[j]);
}
thefile.close();
}
Are all your swatches named? Does this do it for you:
var listfile = "~/Desktop/Name.csv"; //add Filename
var doc = activeDocument;
var col = doc.swatches;
var info = new Array();
if(doc.documentColorSpace == DocumentColorSpace.CMYK)
{
info.push("I.D.,C,M,Y,K");
for(var i = 0; i < col.length;i++)
{
if(col[i].color=="[CMYKColor]")
{
var name1 = col[i].name;
var c = Math.round(col[i].color.cyan);
var m = Math.ro
...
Copy link to clipboard
Copied
Are all your swatches named? Does this do it for you:
var listfile = "~/Desktop/Name.csv"; //add Filename
var doc = activeDocument;
var col = doc.swatches;
var info = new Array();
if(doc.documentColorSpace == DocumentColorSpace.CMYK)
{
info.push("I.D.,C,M,Y,K");
for(var i = 0; i < col.length;i++)
{
if(col[i].color=="[CMYKColor]")
{
var name1 = col[i].name;
var c = Math.round(col[i].color.cyan);
var m = Math.round(col[i].color.magenta);
var y = Math.round(col[i].color.yellow);
var k = Math.round(col[i].color.black);
info.push(name1+","+c+","+m+","+y+","+k);
} else {info.push(i);}
}
}
if(doc.documentColorSpace == DocumentColorSpace.RGB)
{
info.push("I.D.,R,G,B");
for(var i = 0; i < col.length;i++)
{
if(col[i].color=="[RGBColor]")
{
var name2 = col[i].name;
var r = Math.round(col[i].color.red);
var g = Math.round(col[i].color.green);
var b = Math.round(col[i].color.blue);
info.push(name2+","+r+","+g+","+b);
} else {info.push(i);}
}
}
var thefile = new File(listfile); //pass the file to a Variable
var isopen = thefile.open("w"); //open file for editing
if (isopen)//test file is open
{
thefile.seek(0,0);
for(var j = 0; j < info.length; j++)
{
thefile.writeln(info[j]);
}
thefile.close();
}
Copy link to clipboard
Copied
Yes they are named and yes it worked perfectly! You are an wizard! Thank you!!!
Copy link to clipboard
Copied
I'm trying to use this scipt to create the same type of list in CMYK. I've changed the listfile path and changed the var doc line to my .ai file and both the .csv file and .ai file open. Getting a script error. Screen shot attached.
NOTE: I'm on Mac OS 12.6 using Script Editor with preferences set to Javascript.
Copy link to clipboard
Copied
The Script Editor in Mac OS is not used to write Adobe scripts. That's why you see errors like this. Save the script as .js and run it directly in Adobe Illustrator.
Copy link to clipboard
Copied
I'm trying to create the same type of spreadsheet as the OP but CMYK instead of RGB which it looks like the script is already set up for. I think I'm close to getting it to work but need a few tweaks. See reply to lackostration below.
Thanks!