• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Convert CSV to Swatch Library?

New Here ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

11.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guru ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

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.remove();

          } */

          for (var a = 0; a < fileArray.length; a++) {

               var n = fileArray[0]; // First Column is name              

               if (n == 'Cyan' || n == 'Magenta' || n == 'Yellow' || n == 'Black') {         

                    n = n + '-???'; // Reserved swatch name;

               }         

               r = parseFloat(fileArray[1]); // Second Column is Red

               g = parseFloat(fileArray[2]); // Third Column is Green

               b = parseFloat(fileArray[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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2012 Aug 07, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2012 Aug 07, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2012 Aug 07, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 22, 2013 Feb 22, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 22, 2013 Feb 22, 2013

Copy link to clipboard

Copied

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…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 23, 2013 Feb 23, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 23, 2013 Feb 23, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

Hello! 

 

First, thank you so much for the code. I'm creating palletes of entire lines of yarns based upon normalized images of the fiber. (Yes, I'm a dork.) 

 

This is going to be a huge undertaking, and adding it all to ID manually would drive me crazy. (Crazier.) 

 

When running the script, I select the CSV file, and get the following error: 

 

Error Number: 55

Error String: Object does not support the property or method 'swatchGroups'

 

Engine: main

File: <path to my file> 

Line: 32

Source: var swatchgroup = docRef.swatchGroups.add();

 

Thoughts?

 

Aloha!

meri

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

LATEST

Hi meri, did you say ID? this is an Illustrator Script, it won't work on ID as is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

Here's what I get

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

[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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 04, 2014 Feb 04, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines