Hi everyone ![]()
I have a list of 300+ colors that I need to make into a swatch library for Illustrator. The data looks like this:
GREEN GRASS,127,187,0
PALE YELLOW,241,235,135
LIGHT YELLOW,238,231,93
DAFFODIL,249,231,21
MOONBEAM,249,223,22
etc.
It's RGB I think. In any case, I am just starting with Illustrator and I know NOTHING about scripting. Can anyone help me get aaaaalllll these colors into a swatch library, please? I am getting a migraine just thinking about putting them in one by one.
LOL
I found something here, but that didn't work for me. I get an error on processing on line 75. http://forums.adobe.com/message/2877951
Error 24: app.doScript is not a function, Line 75 _> app.dpScript(speakThis, 1095978087); //AppleScript.
I get as far as choosing the csv file, and then I get the error. I think this outputs as CMYK, but not sure. Does anyone know of another script, or can anyone help me out?
Thanks,
Gina
Hi ![]()
I went looking for the other thread you said was started in the last couple of days and found it. My search terms didn't pick it up for some reason..Oh, I found the thread I referenced by google so it must not have parsed the newer thread yet. I was desperate so I tried the script in the older thread, lol. I didn't know if it would work or not. Um..not. ![]()
I have a windows pc, btw.
I was hoping there would be something out there I could use without bothering anyone, but I haven't seen anything. I'd appreciate the help, but I can understand that someone creating the script for me is a big favor. The thread is two years old, so I think it's understandable that you don't remember it, lol.
Thanks,
Gina
Muppet's script was for InDesign -- I guess so it could save the swatches as an .ASE file. Illustrator's Javascript lacks this command ...
Here is a variant, based upon MM's, but stripped of all ID specific stuff. This one creates your new swatches in the current document; it creates a new swatch group with the CSV file name.
function main() {
if (isOSX()) {
var csvFile = File.openDialog('Select a CSV File', function (f) { return (f instanceof Folder) || f.name.match(/\.csv$/i);} );
} else {
var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;');
}
if (csvFile != null) {
fileArray = readInCSV(csvFile);
var columns = fileArray[0].length;
//alert('CSV file has ' + columns + ' columns…');
var rows = fileArray.length;
//alert('CSV file has ' + rows + ' rows…');
if (columns == 4 && rows > 0) {
exchangeSwatches(csvFile);
} else {
var mess = 'Incorrect CSV File?';
isOSX ? saySomething(mess) : alert(mess);
}
} else {
var mess = 'Ooops!!!';
isOSX ? saySomething(mess) : alert(mess);
}
}
main();
function exchangeSwatches(csvFile) {
// var docRef = app.documents.add();
var docRef = app.activeDocuments;
var swatchgroup = docRef.swatchGroups.add();
swatchgroup.name = csvFile.name;
with (docRef) {
/* for (var i = swatches.length-1; i >= 0; i--) {
swatches[i].remove();
} */
for (var a = 0; a < fileArray.length; a++) {
var n = fileArray[a][0]; // First Column is name
if (n == 'Cyan' || n == 'Magenta' || n == 'Yellow' || n == 'Black') {
n = n + '-???'; // Reserved swatch name;
}
r = parseFloat(fileArray[a][1]); // Second Column is Red
g = parseFloat(fileArray[a][2]); // Third Column is Green
b = parseFloat(fileArray[a][3]); // Forth Column is Bloo
if (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255) {
var color = new RGBColor;
color.red = r;
color.green = g;
color.blue = b;
var swatch = swatches.add();
swatch.name = n;
swatch.color = color;
swatchgroup.addSwatch(swatch);
} else {
var mess = 'Color values are out of range?';
isOSX ? saySomething(mess) : alert(mess);
}
}
}
}
function readInCSV(fileObj) {
var fileArray = new Array();
fileObj.open('r');
fileObj.seek(0, 0);
while(!fileObj.eof) {
var thisLine = fileObj.readln();
var csvArray = thisLine.split(',');
fileArray.push(csvArray);
}
fileObj.close();
return fileArray;
}
function saySomething(stringObj) {
var speakThis = 'I say, "' + stringObj + '"';
alert(speakThis);
}
function isOSX() {
return $.os.match(/Macintosh/i);
}
Oh, thank you very much Jongware
However, I get an error when using the script ![]()
Error 21; undefined is not an object.
Line 30
-> var swatchgroup=docRef.swatchGroups.add();
I copied and pasted the above code into Notepad, then saved as a .js, ran the script within Illustrator CS5. It asked for the csv file, then gave me the error.
Larry, that fixed the problem! Now I have a swatch library of all 300 colors
Woohoo! Thank you Jongware, for the script, and Larry for catching the error! I have health issues that keep my time on the computer very limited. This would have taken me weeks to do one by one (if I ever managed to get it done at all), so I thank you so much for the script that did it in... less than a minute.
This is fantastic!!!
I really appreciate the time and effort. You did me a huge favor and I can't thank you enough.
This is one happy gal.
Any of you brave script writers want to take on another challenge? I've visited colormunki.com and played around with the Munsell color swatch/pallette app, and have managed to save ALL of the swatches in csv files. There are 40 files, one for each hue. Each csv file has four columns:
I attempted to modify the scripts in this thread, but was a bit out of my league. There are seperate attributes/properties/classes, etc. for lab colors, and after getting a migraine headache, I threw in the towel. Below is a link to the zip file that contains the 40 csv files, if anyone wants to take a stab at it. AFAIK, since the colormunki site allows visitors to download the swatch data, I'm assuming it's ok to post this link. All due credit to colormunki.com and Munsell Color. (not sure why they don't just allow visitors to download entire Munsell library in one zip file)
I have not checked the files individually, so there may be a mistake here and there (missing color maybe, or double entry of a color) -- but it should be pretty clean.
Message was edited by: brandtryan
North America
Europe, Middle East and Africa
Asia Pacific