Skip to main content
Inspiring
April 20, 2024
Answered

create an ase file starting from a csv file

  • April 20, 2024
  • 1 reply
  • 4913 views

Hi everyone, I would like to create an ase file (color library) starting from a csv file. The file consists of name,r,g,b,c,m,y,k (CH1 0001, 233,238,235, 11,4,9,0)
I tried with chatgpt's suggestions but with a thousand errors and unreadable files I didn't solve anything.
Since there are 1170 colors, doing it by hand is time-consuming and potentially leads to possible errors... I would like to understand if it can be automated in some way.

I use Windows 10.

 

Thanks to everyone

This topic has been closed for replies.
Correct answer jduncan

I tried leaving 4 columns, thus excluding the cmyk values. I'm using a test file with a few values for now, and it gives me an incorrect csv error. trying with a csv with a single column, I get error in line 55. I don't understand where I'm going wrong


@Alex32252670s8p0, below is a script that should work with the sample CSV format you uploaded (as '1.PNG'). Please note, this is just a simple example script that only works with RGB values provided in the exact format you specified. Let me know if you have any questions... Cheers!

 

// Generate an Ai Swatch Group from RGB values in a CSV file (in the following format).
//
// name,RED,GREEN,BLUE
// color 1,1,1,160
// two,2,92,2
// three,253,3,3
//
// PLEASE NOTE: This script is only an example in response to the Adobe forum question below.
// https://community.adobe.com/t5/illustrator-discussions/create-an-ase-file-starting-from-a-csv-file/td-p/14568361

(function () {
  function parseCSV(data) {
    var lines = data.split("\n");
    var rows = [];
    for (var i = 0; i < lines.length; i++) {
      if (lines[i] == "") continue;
      rows.push(lines[i]);
    }
    return rows;
  }

  function readFile(file) {
    try {
      file.encoding = "UTF-8";
      file.open("r");
      var data = file.read();
      file.close();
      return data;
    } catch (e) {
      "Error!\nFile could not be read.\n" + e;
    }
  }

  var doc = app.activeDocument;
  var swatches = app.activeDocument.swatches;

  // choose the csv file
  var file = File.openDialog("Select CSV File");

  // parse the csv data
  var rows = parseCSV(readFile(file), true);

  // check for actual csv data
  if (rows.length < 1) {
    alert("Error!\nNo CSV data.");
  }

  // setup the swatch group
  var swatchGroup = doc.swatchGroups.add();
  swatchGroup.name = decodeURI(file.name);

  // make a swatch for each row (skip header row (pos 0))
  var row, name, r, g, b, color, swatch;
  for (var i = 1; i < rows.length; i++) {
    row = rows[i].split(",");
    name = row[0].toString();
    r = parseFloat(row[1]);
    g = parseFloat(row[2]);
    b = parseFloat(row[3]);

    // check for proper RGB values
    if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
      alert(
        "Error!\nColor '" + name + "' has out of range values and will be skipped."
      );
      continue;
    }

    //
    color = new RGBColor();
    color.red = r;
    color.green = g;
    color.blue = b;
    swatch = swatches.add();
    swatch.name = name;
    swatch.color = color;
    swatchGroup.addSwatch(swatch);
  }
})();

1 reply

Monika Gause
Community Expert
April 20, 2024

You could check out this: https://community.adobe.com/t5/illustrator-discussions/convert-csv-to-swatch-library/m-p/4377683

 

There might be other scripts in this forum.

Inspiring
April 21, 2024

Bye thank you. I had seen that page but among the many suggestions I couldn't find a solution. All codes give me errors

Inspiring
April 22, 2024

Just checked, I have no spaces. The csv has 4 columns, and if I open it with notepad I have the symbol ; as a column separator. Opened in Excel I checked the absence of spaces. I attach the file I'm using


Wait... I used your file, which instead is all in a single column and in fact the separator is a ,
And your code works perfectly