• 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

13.2K

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

Copy link to clipboard

Copied

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)

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

please post your csv file to analyze

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Hello,

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

Thanks!

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

Copy link to clipboard

Copied

Nope, had to do it manually afterall.

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

Copy link to clipboard

Copied

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

 

 

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

Thank you!!

 

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