23 Replies Latest reply: Feb 4, 2014 8:25 PM by Silly-V RSS

    Convert CSV to Swatch Library?

    Ginakra67 Community Member

      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

        • 1. Re: Convert CSV to Swatch Library?
          Muppet Mark Community Member

          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 )

          • 2. Re: Convert CSV to Swatch Library?
            Ginakra67 Community Member

            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

            • 3. Re: Convert CSV to Swatch Library?
              [Jongware] MVP

              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);
              }
              
              • 4. Re: Convert CSV to Swatch Library?
                Ginakra67 Community Member

                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.

                • 5. Re: Convert CSV to Swatch Library?
                  Larry G. Schneider MVP

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

                  • 6. Re: Convert CSV to Swatch Library?
                    Ginakra67 Community Member

                    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.

                    • 7. Re: Convert CSV to Swatch Library?
                      [Jongware] MVP

                      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.

                      • 8. Re: Convert CSV to Swatch Library?
                        Ginakra67 Community Member

                        Just wanted to say thank you, again !! I am happily using my 300 color swatch library, it's awesome! Thanks a bunch for saving me a HUGE amount of time and at least four migraines, and for doing me such a huge favor, Jongware. I really appreciate it

                        • 9. Re: Convert CSV to Swatch Library?
                          brandtryan Community Member

                          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

                          • 10. Re: Convert CSV to Swatch Library?
                            Muppet Mark Community Member

                            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…

                            • 11. Re: Convert CSV to Swatch Library?
                              brandtryan Community Member

                              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

                              • 12. Re: Convert CSV to Swatch Library?
                                brandtryan Community Member

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

                                • 13. Re: Convert CSV to Swatch Library?
                                  mutagenicpixels Community Member

                                  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

                                  • 14. Re: Convert CSV to Swatch Library?
                                    Larry G. Schneider MVP

                                    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)

                                    • 15. Re: Convert CSV to Swatch Library?
                                      mutagenicpixels Community Member

                                      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.

                                      • 16. Re: Convert CSV to Swatch Library?
                                        Larry G. Schneider MVP

                                        Here's what I get

                                         

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

                                        • 17. Re: Convert CSV to Swatch Library?
                                          [Jongware] MVP

                                          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?

                                          • 18. Re: Convert CSV to Swatch Library?
                                            mutagenicpixels Community Member

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

                                            • 19. Re: Convert CSV to Swatch Library?
                                              [Jongware] MVP

                                              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.

                                              • 20. Re: Convert CSV to Swatch Library?
                                                mutagenicpixels Community Member

                                                [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

                                                • 21. Re: Convert CSV to Swatch Library?
                                                  [Jongware] MVP

                                                  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.

                                                  • 22. Re: Convert CSV to Swatch Library?
                                                    mutagenicpixels Community Member

                                                    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

                                                    • 23. Re: Convert CSV to Swatch Library?
                                                      Silly-V Community Member

                                                      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)