Skip navigation
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:
  • Currently Being Moderated
    Feb 3, 2014 1:42 PM   in reply to [Jongware]

    Jongware, this is giving me the following error (using Illustrator CS5.5):

     

    Error 21: undefined is not an object.

    Line: 9

    -> var columns = fileArray[0].length;

     

    I'm in dire need of this script as well to quickly digest 900+ swatches :/

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2014 2:30 PM   in reply to mutagenicpixels

    What's the setup of your CSV files? Is this for RGB or CMYK colors. The script above is for RGB. If for CMYK, change the number of of columns to 5 (Name,Cvalue,Mvalue,Yvalue,Kvalue)

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2014 2:41 PM   in reply to Larry G. Schneider

    Thank you for replying so rapidly Larry! This is for RGB and my CSV file is setup as followed:

     

    Aloe 309,167,217,172

    Alpine 468,75,175,218

    Aluminum 052,178,178,187

    Amazon 313,119,149,85

    Ambrosia 337,143,184,164

     

    The number after the name is the colour code and the three numbers at the end are RGB values.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2014 4:31 PM   in reply to mutagenicpixels

    Here's what I get

     

    Screen shot 2014-02-03 at 4.28.40 PM.png

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 1:35 AM   in reply to Larry G. Schneider

    Dave, I agree with Larry -- there seems nothing wrong with my script:

     

    aloe.png

     

    I get the error message you mentioned if I save a file as a Word document and then manually rename it to CSV. Of course that will not work -- CSV files are supposed to be plain ASCII text. Could this be a PICNIC problem?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 5:40 AM   in reply to [Jongware]

    I created the CSV using Excel (also attempted it in TextEdit) and edited the script using ExtendedScript Toolkit

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 6:33 AM   in reply to mutagenicpixels

    mutagenicpixels wrote:

     

    I created the CSV using Excel (also attempted it in TextEdit) and edited the script using ExtendedScript Toolkit

     

    It works for both Larry and me, as you can see. These are actual Illustrator screen shots, not Photoshopped or otherwise mocked up.

     

    Did you know that Mac OS X's TextEdit by default does not save a new file as plain text, but as RTF instead? If that is not the issue here (and you are aware of the difference between a plain text file and any other sort -- and know how to check), then there must be a fundamental mis-understanding somewhere.

     

    For the moment, I'm going to stick to my PICNIC diagnostic.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 6:53 AM   in reply to [Jongware]

    [Jongware] wrote:

     

    Did you know that Mac OS X's TextEdit by default does not save a new file as plain text, but as RTF instead?

     

    Quite aware of that. Besides if I was saving in Excel and LibreOffice into a new file it would have nothing to do with TextEdit's rtf now would it?

     

    I don't think you're shopping or mocking it up, but writing "Mine works, so yours should" doesn't solve anything. Perhaps I should contact the original scripts creator instead of your knockoff

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 7:30 AM   in reply to mutagenicpixels

    Equally, noting "it does not work for me, please help" as the problem on your end does nothing to help us help you.

     

    As I said, I am able to get the error you got -- by pointing the script to an invalid CSV file. Perhaps, if you upload your file somewhere on a public server, we can trouble-shoot that part.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 7:37 AM   in reply to [Jongware]

    I replied same way as Ginakra67 with quite different results, that's not my problem that's yours...

     

    Anyway if you're so inclined: http://we.tl/xClDg660MU

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 4, 2014 8:25 PM   in reply to mutagenicpixels

    I opened your file in Excel and it looked the way I expected it to.  I opened it in Notepad and all of your text is in one line.  I saved another CSV from my Excel (choosing Comma-separated Values csv, not the MSDOS ones or anything), and opened the new one in Notepad and the text was in columns & rows now.  I must therefore advise that it is an issue with your text file.  (O_o)

     
    |
    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