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

Convert CSV to Swatch Library?

New Here ,
Aug 04, 2012 Aug 04, 2012

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
15.6K
Translate
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
Explorer ,
Feb 04, 2014 Feb 04, 2014

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

Translate
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
Valorous Hero ,
Feb 04, 2014 Feb 04, 2014

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)

Translate
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 ,
Apr 17, 2019 Apr 17, 2019

Hi,
Is there some way to modify this script to work with pantone color7

Translate
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 Beginner ,
Oct 11, 2016 Oct 11, 2016

hi there, 

does anyone have an idea how to do the exact opposite? I found this thread because I have a list of CMYK swatches saved as spot colors in an ASE file and I want to parse them into CSV/TDV to bring them into Excel, where I can revise the data to import into another database.

Translate
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
Valorous Hero ,
Oct 11, 2016 Oct 11, 2016

Hey DCardillo​ - you can start off with this script snippet:

#target illustrator

function test(){

  var doc = app.activeDocument;

  var arr = [["name", "cyan", "magenta", "yellow", "black"]], thisSwatch, thisSwatchColorSpotColor;

  for(var i = 0;  i < doc.swatches.length;  i++){

    thisSwatch = doc.swatches;

    if(thisSwatch.color.typename != "SpotColor"){

        continue;

    }

    thisSwatchColorSpotColor = thisSwatch.color.spot.color;

    if(thisSwatchColorSpotColor.typename != "CMYKColor"){

        continue;

    }

    arr.push([

      thisSwatch.name,

      Math.floor(thisSwatchColorSpotColor.cyan),

      Math.floor(thisSwatchColorSpotColor.magenta),

      Math.floor(thisSwatchColorSpotColor.yellow),

      Math.floor(thisSwatchColorSpotColor.black)

    ]);

  };

  var newFile = File("~/Desktop/SwatchList.csv");

  newFile.open("w");

  newFile.write(arr.join("\n"));

  newFile.close();

};

test();

Translate
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 ,
Jul 21, 2016 Jul 21, 2016

Hello Everyone,

I have used the script for the export of the .csv file to create the color swatches using RGB values and this works OK.

But there is a problem that it adds QUOTES to the beginning of the name after exported, is there any way these QUOTES can be removed or not be added wile exporting?

these swatches can be renamed one by one but I would like to rename them all at once, I have used a renaming script but it does not recognize these quotes at the beginning of each swatch name. it changes the name bu the quotes.

Thank you all for any help you can provide and it will be well appreciated it.

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

I couldn't make this work under CC.
It keeps giving me back this message:
Color values are out of range?

Can anyone help what to change to be able to use it in CC? Thank you

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

please post your csv file to analyze

Translate
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 ,
Sep 24, 2020 Sep 24, 2020

Thanks for the quick reply. 

the content of the csv file is:

name,RED,GREEN,BLUE
one,1,1,1
two,2,2,2
three,3,3,3

https://www.dropbox.com/sh/9dvyz1vb7j3aqnx/AAC_WGTDBhVI8_3fgo0J9dkBa?dl=0

Translate
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 ,
Dec 02, 2020 Dec 02, 2020

Hello,

I am getting the same error.  Did you figure out what the issue was?

Thanks!

Translate
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 ,
Dec 02, 2020 Dec 02, 2020

Nope, had to do it manually afterall.

Translate
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
Advocate ,
Dec 03, 2020 Dec 03, 2020

Here are both scripts...(Adobe has destroyed the original ones)

 

#target illustrator

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.activeDocument;
    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);
}
#target illustrator

function test(){
  var doc = app.activeDocument;
  var arr = [["name", "cyan", "magenta", "yellow", "black"]], thisSwatch, thisSwatchColorSpotColor;
  for(var i = 0;  i < doc.swatches.length;  i++){
    thisSwatch = doc.swatches[i];
    if(thisSwatch.color.typename != "SpotColor"){
        continue;
    }
    thisSwatchColorSpotColor = thisSwatch.color.spot.color;
    if(thisSwatchColorSpotColor.typename != "CMYKColor"){
        continue;
    }
    arr.push([
      thisSwatch.name,
      Math.floor(thisSwatchColorSpotColor.cyan),
      Math.floor(thisSwatchColorSpotColor.magenta),
      Math.floor(thisSwatchColorSpotColor.yellow),
      Math.floor(thisSwatchColorSpotColor.black)
    ]);
  };
  var newFile = File("~/Desktop/SwatchList.csv");
  newFile.open("w");
  newFile.write(arr.join("\n"));
  newFile.close();
};
test();

 

 

Translate
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 ,
Dec 07, 2020 Dec 07, 2020

Thank you so much for this! I don't know if it is a PC or Mac thing but I had to take the s off of documents in lines 31 and 32 to make it work on my Mac.  After I did that, it worked beautifully in Illustrator 2021.

Translate
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 ,
Apr 04, 2021 Apr 04, 2021

Hi kings_freak! Could you send to me your adjusted script? I have the same problem...

Thank you!!

 

Translate
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