Importing Color to Swatch Library from Text File

New Here ,
May 19, 2010 May 19, 2010

Copy link to clipboard

Copied

Hi,

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?

Thanks!

TOPICS
Scripting

Views

10.1K

Likes

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

correct answers 1 Correct Answer

Guide , Jun 08, 2010 Jun 08, 2010
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...

Likes

Translate

Translate
Adobe Community Professional ,
May 19, 2010 May 19, 2010

Copy link to clipboard

Copied

Try reading through this

http://forums.adobe.com/thread/623432?tstart=0

Likes

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
Engaged ,
May 20, 2010 May 20, 2010

Copy link to clipboard

Copied

Hi,

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 )

art.chrome

Likes

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
Guide ,
May 20, 2010 May 20, 2010

Copy link to clipboard

Copied

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…

Likes

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 ,
Jun 07, 2010 Jun 07, 2010

Copy link to clipboard

Copied

Hi,

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!


AM

Likes

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
Guide ,
Jun 08, 2010 Jun 08, 2010

Copy link to clipboard

Copied

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:

Red,0,100,100,10

Orange,0,65,100,0

Yellow,0,10,100,0

Green,70,40,100,0

Blue,100,50,0,20

Violet,50,100,20,0

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) {                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();      with (docRef) {                for (var i = unusedSwatches.length-1; i >= 0; i--) {                unusedSwatches.remove();           }           for (var a = 0; a < fileArray.length; a++) {                var b = fileArray[0]; // First Column is name                               if (b == 'Cyan' || b == 'Magenta' || b ==...[1]); // Second Column is Cyan                m = parseFloat(fileArray[2]); // Third Column is Magenta                y = parseFloat(fileArray[3]); // Forth Column is Yellow                k = parseFloat(fileArray[4]); // Fifth Column is Black                if (c >= 0 && c <= 100 && m >= 0 && m <= 100 && y >= 0...

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

Likes

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 ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Muppet Mark,

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

Cheers!

Likes

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

Copy link to clipboard

Copied

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

Thanks!

Dave

Likes

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

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.

Likes

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 ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

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.

​Registration

#646464

Paper

#000000

Black

#000000

@@FillSolidBackground@@

#525252

@@SliderBar@@

#8C8C8C

@@HamburgerMenu@@

#FFFFFF

​@@Outline@@

​<Not Available Yet>

​@@MenuText@@

​#FFFFFF

​@@ThisSwatchDoesNotExist@@

​#00FF00

​@@Shadow@@

​#999999

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

​Many Thanks!!

Likes

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 ,
Feb 28, 2019 Feb 28, 2019

Copy link to clipboard

Copied

Hi! I’m new to scripting in Adobe - this script will do exactly what I need, but I’m unsure exactly how to make it work. What language is it written in/how do I properly compile it so that I can run it in InDesign?

Likes

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 Community Professional ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

copy the script, paste into a plain text editor, save as *.jsx

but it may not work in inDesign, this is an Illustrator Script.

Likes

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

Copy link to clipboard

Copied

Is there anyway to get this script updated for 2020? i tried to run it and nothing happened. When i went into it to check it out it says #target Indesign, so itried to run it in Indesign and still nothing. Not sure if Mark still posts here, but i have had some help from you Carlos in the past.

Likes

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 Community Professional ,
Dec 24, 2020 Dec 24, 2020

Copy link to clipboard

Copied

sorry Muppet Mark hasn't posted in a while and the script is incomplete and it's for indesign

 

try the scripts in these posts and let us know if they work

https://community.adobe.com/t5/illustrator/convert-csv-to-swatch-library/m-p/4377683?page=1#M152596

 

https://community.adobe.com/t5/illustrator/csv-to-swatch-library-script-problems/m-p/10915694?page=1...

Likes

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

Copy link to clipboard

Copied

Thanks, So i'm using this script below, , when i select the CSV file it says "I say "Incorrect CSV file?"

My CSV file has 5 columns here is the first 2-3 lines. Not sure why the CSV is incorrect.

NameCyanMagentaYellowBlack
Spring Yellowish Green220520
Olive Green50387711

 

#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.activeDocuments;
    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);
}

 

Likes

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 Community Professional ,
Dec 25, 2020 Dec 25, 2020

Copy link to clipboard

Copied

the original script was written for RBG colors

 

try this version for CMYK

// https://community.adobe.com/t5/illustrator/importing-color-to-swatch-library-from-text-file/m-p/11704614?page=1#M257125

// jongware/MuppetMark

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) {
            exchangeSwatches(csvFile);
        } else {
            var mess = 'Incorrect CSV File, it should have 5 columns: Swatch Name, C, M, Y, K';
            isOSX ? saySomething(mess) : alert(mess);
        }
    } else {
        var mess = 'Cancelled by User';
        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 = 1; 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;  
            }
            c = parseFloat(fileArray[a][1]); // Second Column is Red  
            m = parseFloat(fileArray[a][2]); // Third Column is Green  
            y = parseFloat(fileArray[a][3]); // Forth Column is Bloo  
            k = parseFloat(fileArray[a][4]); // Forth Column is Bloo  
            if (c >= 0 && c <= 100 && m >= 0 && m <= 100 && y >= 0 && y <= 100 && k >= 0 && k <= 100) {
                var color = new CMYKColor;
                color.cyan = c;
                color.magenta = m;
                color.yellow = y;
                color.black = k;
                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);
}

Likes

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 ,
Feb 08, 2021 Feb 08, 2021

Copy link to clipboard

Copied

I get a JavaScript error when I try to run this:

Error Number 55

Error String: Object does not support the property or method 'swatchGroups'

Line: 35

Source:     var swatchgroup = docRef.swatchGroups.add();

Any thoughts on how to resolve it? I'm pretty sure my CSV file is compliant (name,c,m,y,k). Running InDesign CC 13.1.

Likes

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 Community Professional ,
Feb 08, 2021 Feb 08, 2021

Copy link to clipboard

Copied

the script is for Illustrator, it won't work in InDesign.

Likes

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 ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

LATEST

Thanks for your input. In case anyone is searching for a solution in the future, I finally found an InDesign script that does this (converts CSV to ASE for CMYK):

http://kasyan.ho.ua/indesign/swatch_color/import_colors_from_csv.html

Cheers

Likes

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