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

create an ase file starting from a csv file

Explorer ,
Apr 20, 2024 Apr 20, 2024

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

TOPICS
Import and export , Scripting , Third party plugins , Tools
1.9K
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

correct answers 1 Correct answer

Community Expert , Apr 22, 2024 Apr 22, 2024

@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 
...
Translate
Adobe
Community Expert ,
Apr 20, 2024 Apr 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.

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 20, 2024 Apr 20, 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

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 ,
Apr 21, 2024 Apr 21, 2024

You know how to make that code into a script and then run it?

 

Please describe your issues and maybe you can also share a sample of your CSV so someone might be able to help you with the code.

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 21, 2024 Apr 21, 2024

I know little about programming and for the tests I did I used visualcode and the codes generated by chatgpt. Every time I tried a code I always got different errors, and the few times I got a result it was an empty or incompatible ase file. I'll leave a small example of the csv file I'm using

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 ,
Apr 21, 2024 Apr 21, 2024

And the code from that forum page I linked? 

You know how to make that into a script?

And which errors popped up?

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 21, 2024 Apr 21, 2024

I'm not familiar with codes and scripts. I tried it and I get an alert saying "i say, incorrect csv file?". from what I read in the code, the file must have 4 columns, I tried but the result is always that message. I have no other info

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 ,
Apr 21, 2024 Apr 21, 2024

Your file has 8 columns. For that script your CSV file needs to be made in a certain way in order to work. You can see that in the first post. First column: name of the swatch, then follow the RGB values. If you want it to work with different CSV structure, then it needs to be reritten

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 21, 2024 Apr 21, 2024

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

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 ,
Apr 22, 2024 Apr 22, 2024

@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);
  }
})();
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 22, 2024 Apr 22, 2024

Hello and thanks to you too. Your code gives me this error (see attachment). The csv is the one I posted yesterday and the illustrator document is set as rgb. It gives me error in line 76

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 ,
Apr 22, 2024 Apr 22, 2024

@Alex32252670s8p0, you must have some junk inside of your CSV file. I recreated your exact CSV file by hand (see attached) and it works just fine. A CSV is just a simple text file but software like Excel or Google Sheets can sometimes put junk into the file. Please upload your actual CSV file to a new comment (not a screenshot) and we can have a closer look.

name,RED,GREEN,BLUE
color 1,1,1,160
two,2,92,2
three,253,3,3
...

 

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 22, 2024 Apr 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

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 22, 2024 Apr 22, 2024

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

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 ,
Apr 22, 2024 Apr 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.

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 22, 2024 Apr 22, 2024
LATEST

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

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