Skip navigation
Ginakra67
Currently Being Moderated

Convert CSV to Swatch Library?

Aug 4, 2012 2:37 PM

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

 
Replies
  • Currently Being Moderated
    Aug 5, 2012 6:08 AM   in reply to Ginakra67

    Funny, someone has just asked a similar question only this last couple of days… My memory is shot I don't recall that script at all… It will error at that line because Illustrator doesn't have a method to do AppleScript… ( it only makes the mac speak the errors anyhow )

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 5:43 AM   in reply to Ginakra67

    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);
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 2:51 PM   in reply to Ginakra67

    The line before the error should be  var docRef = app.activeDocument; not var docRef = app.activeDocuments;

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 12:15 PM   in reply to Ginakra67

    What a weird error to leave in ... I must've done "one slight adjustment" just prior to copying -- usually I make sure it works as advertised! Thanks to eagle-eyed Larry for correcting it.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2013 8:09 AM   in reply to Ginakra67

    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:

     

        1. Sample Name (2.5R, etc.)
        2. L* (lightness)
        3. a* (Red for pos #s and Green for neg #s)
        4. b* (Yellow for pos #s and Blue for neg #s)

     

    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)

     

    http://sdrv.ms/159bnaC

     

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2013 1:50 PM   in reply to brandtryan

    Had a quick look reading the data is simple enough… I didn't look at the legality of this… Do you have AI, ID or both…? I used ID in the original linked post as it can save to an *.ase file which can be used throughout the suite…

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 23, 2013 2:06 AM   in reply to Muppet Mark

    I've got both -- (creativec cloud subscription).  An .ase would be great! 

     

    Somehow managed to miss seeing the "neutral" tabs on the colormunki site  -- going to create csv files for those as well

     

    Message was edited by: brandtryan

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 23, 2013 2:15 AM   in reply to brandtryan

    I've updated the original link to the csv files -- the new .zip contains the additional 40 neutral swatches (white to black)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points