9 Replies Latest reply on Feb 3, 2017 12:44 AM by C0FF33

    Importing Color to Swatch Library from Text File

    amemme Level 1


      I have a large list of custom colors in Excel that has the color name and CMYK breakdown of each color. I'm looking for a way to import this information to create a custom Color Swatch Library. That will have the name of the color and the CMYK breakdown. So that I can easily use in Illustrator and Photoshop. Is there any way or application in doing this with out manually entering the information and creating a new library?



        • 2. Re: Importing Color to Swatch Library from Text File
          artchrome Level 3



          Moreover that Muppet Mark said, you can also see this post to read text file / csv file , but becarfull if you have a CR / LF characters in a cell

          May be have you a sample of your text file ?


          ( to Muppet Mark )



          • 3. Re: Importing Color to Swatch Library from Text File
            Muppet Mark-QAl63s Level 4

            Save the Excel file out as CSV or TDT. Have a script read this text file into a set of arrays create swatches from the array info. Do you wish for these swatches to be useable in the GUI or do you want access to them via script at a later date? I would use Indesign to do the swatch creation myself as an ID document has the 'saveSwatches()' method which will allow you to save to file as 'ase' this can be shared amongst Adobe apps…

            • 4. Re: Importing Color to Swatch Library from Text File
              amemme Level 1


              Thanks for the input. Yes I am looking at using them through the GUI. I'm not very familiar with scripting so you will have to excuse my ignorance. Is the script that you mention to convert the CSV file to an array a script that I would be able to download online? I tried to do a search and got several results for different programming language. As well once I have the array file how do I import that into indesign so that it will recognize it as a swatch?


              The following is an example of the data that I am putting in.

              Name    Cyan    Magenta    Yellow    Black
              1001    95    0    69    78
              1007    53    0    60    0
              1012    35    0    83    0
              1017    100    0    85    14


              Thanks for you help!


              • 5. Re: Importing Color to Swatch Library from Text File
                Muppet Mark-QAl63s Level 4

                From Excel you save your file out as text using something to delimit the values 'comma' CSV and 'tab' TDT are the common ones to use. A script can then read this information in. I started this script using CS2 and Indesign I don't think you could save '.ase' from any other Adobe app. Things may have changed but Im buried taking a look at the CS5 trial to put any time into this just now. Only 24 days left… I did open and run and it still worked so you may get some mileage. I did start to add RGB and LAB as switches but that may have to come L8R… When I can start to use dialogs… CSV should be like:









                The sample script…

                #target indesign
                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 == 5 && rows > 0) {
                          } else {
                               var mess = 'Incorrect CSV File?';
                               isOSX ? saySomething(mess) : alert(mess);
                     } else {
                          var mess = 'Ooops!!!';
                          isOSX ? saySomething(mess) : alert(mess);
                function exchangeSwatches(csvFile) {
                     var docRef = app.documents.add();
                     with (docRef) {     
                          for (var i = unusedSwatches.length-1; i >= 0; i--) {
                          for (var a = 0; a < fileArray.length; a++) {
                               var b = fileArray[a][0]; // First Column is name               
                               if (b == 'Cyan' || b == 'Magenta' || b == 'Yellow' || b == 'Black') {          
                                    b = b + '-???'; // Reserved swatch name;
                               c = parseFloat(fileArray[a][1]); // Second Column is Cyan
                               m = parseFloat(fileArray[a][2]); // Third Column is Magenta
                               y = parseFloat(fileArray[a][3]); // Forth Column is Yellow
                               k = parseFloat(fileArray[a][4]); // Fifth Column is Black
                               if (c >= 0 && c <= 100 && m >= 0 && m <= 100 && y >= 0 && y <= 100 && k >= 0 && k <= 100) {
                                    var colArray = new Array(c, m, y, k);
                                    var col = colors.add({model:ColorModel.process, space:ColorSpace.cmyk, colorValue:colArray, name:b});
                               } else {
                                    var mess = 'Color values are out of range?';
                                    isOSX ? saySomething(mess) : alert(mess);
                          var exchangeSwatches = swatches;
                          var savePath = csvFile.fsName.substring(0, csvFile.fsName.length - 4);
                          var aseFile = new File(savePath + '.ase');
                          saveSwatches(aseFile, exchangeSwatches);
                function readInCSV(fileObj) {
                     var fileArray = new Array();
                     fileObj.seek(0, 0);
                     while(!fileObj.eof) {
                          var thisLine = fileObj.readln();
                          var csvArray = thisLine.split(',');
                     return fileArray;
                function saySomething(stringObj) {
                     var speakThis = 'say "' + stringObj + '" using "Fred"';
                     app.doScript(speakThis, 1095978087); // AppleScript
                function isOSX() {
                  return $.os.match(/Macintosh/i);


                Hope it works 4U… Cyan, Magenta, Yellow & Black are reserved colour names so I just added '-???' as a temporary fix…

                • 6. Re: Importing Color to Swatch Library from Text File
                  amemme Level 1

                  Muppet Mark,

                  Thank you that worked like a charm and was exactly what I was looking for. Saved me a ton of time!



                  • 7. Re: Importing Color to Swatch Library from Text File
                    mutagenicpixels Level 1

                    Hey Muppet Mark! Sorry to trouble you with this but could you modify your script for an RGB csv?




                    • 8. Re: Importing Color to Swatch Library from Text File
                      DCardillo Level 1

                      this is great, and I'm sure going to find a use for it.


                      However what brought me here is the exact opposite problem — I want to parse an ASE file into a CSV, the reverse of what this does.


                      At the end of the day, what I'm trying to do is add a custom swatch palette created in Illustrator/InDesign into GMG ColorProof as custom spot colors. The database import function in ColorProof is a straight TDV file. So I need to get the ASE into Excel, then back out.


                      Every tool I've found so far that did something close only gave me RGB(Hex) values.


                      To be clear, the ASE is CMYK values defined as spot colors, with unique names.

                      • 9. Re: Importing Color to Swatch Library from Text File
                        C0FF33 Level 1

                        Hey MuppetMark

                        I saw that you helped out Amemme with updating InDesign swatches from a excel sheet. I was wondering if you perhaps have a similar script handy for a text file ?

                        ie. I currently have a script which creates a text file from an InDesign document and am now trying fruitlessly to reverse engineer the thing.

                        My file has the name of the swatch, followed by the colour value in a hex format. Some swatch colours aren't defined yet however, so I would want it to skip any swatch colours that contain a greater than or lesser than sign  (<  >)

                        If there happened to be a swatch value in the txt file that doesn't exist in the InDesign document, it would be nice to have a choice to add or ignore it by either remming out one or the other line of code. Mostly I would want to ignore for the time being.

                        Presently this is a sample of how the file looks :

                        All the custom swatch names have the @@ symbols for easy scripting.


















                        <Not Available Yet>







                        If you're able to assist me at all, it would be much appreciated.

                        Many Thanks!!