Skip to main content
Inspiring
April 20, 2024
해결됨

create an ase file starting from a csv file

  • April 20, 2024
  • 1 답변
  • 4913 조회

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

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

Monika Gause
Community Expert
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

Usually, when saving a CSV file (especially from a spreadsheet program) you have the choice to choose the separator. Seems yours was set to a semicolon ";" which is why the script wasn't working. When saving your CSV files, just make sure the set the separator to "," which is usually default.

 

Also note, the CSV parser in my example script is very simple and could break on names or numbers that include a comma.


Probably the separator problem is caused by the system language (Italian in my case). I solved it from notepad by modifying the symbol. Your code is perfect and I don't think I will have problems with decimal values (or decimal values) because I always tend to round them when in cmyk and while in rgb decimal values are not allowed. Thanks again for your precious help