Skip to main content
Participant
June 26, 2013
Question

How to batch generate hundreds of color swatches?

  • June 26, 2013
  • 1 reply
  • 2330 views

- i need to get hundreds of color swatech in tiff (Lab color) format.
- i have table with name of color and its Lab values (columns: name; L value; a value; b value) - table i can save as .csv etc.; script can ask for path to .csv file or can be fixed path and filename
- tiff document can be e.g. 10x10 px or 100x100 px.
- tiff file should be naming according to table value (column "name")
- files can by saved e.g. on disc C: (or user can be ask at the start of the batch)

I am not programmer and I will be thankful if somebody write this script (JavaScript).
I think that it will be useful for many graphic designers.

(Sorry for my English)

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
June 29, 2013

I don’t really get what good that is supposed to do.

What do you intend to do with the tiffs?

Should the tiffs should ultimately be lab?

Could you post (part of) the list you got?

knotomekAuthor
Participant
June 30, 2013

Hello,

i prepare color swatches palette in InDesign.

Generated tiffs (with appropriate description) i linking with data merging engine to specific layout.

I have spectrometer measurement in Lab color space (439 colors).

part of the list:

name  L*  a*  b*
005.8.486015
012.4.593-111
015.5.592112
015.9.486212
026.5.59219
124.8.59411
317.4.594-58
345.9.486-39
0101-093-13
0100-195-13
025-195-413
026-194-26
054-189321
055-192113
056-19307
064-189219
065-192012
083-177715
084-184411
085-19028
093-176914
094-185510
Inspiring
July 1, 2013

I think this should get you close… There are other ways too…

Contains NO error trapping… Files are saved in folder Swatches on your desktop…

#target photoshop

selectCSV();

function selectCSV() {

    if ( /Macintosh/i.test( $.os ) ) {    

        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 ) { var fileArray = readInCSV( csvFile ) };

    var swatches = Folder( Folder.desktop + '/Swatches' );

    if ( ! swatches.exists ) { swatches.create(); }

    createSwatches( fileArray, swatches )

};

function createSwatches( fileArray, saveFolder ) {

    var userUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PIXELS;

    var doc = app.documents.add( 100, 100, 72, 'fluff', NewDocumentMode.LAB, DocumentFill.TRANSPARENT );

    var opts = new TiffSaveOptions();

    opts.byteOrder = ByteOrder.MACOS;

    opts.imageCompression = TIFFEncoding.TIFFLZW;

    opts.layers = false;

    doc.selection.selectAll();

    for ( var i = 0; i < fileArray.length; i++ ) {     

        var n = fileArray[0];    

        var l = parseInt( fileArray[1] );     

        var a = parseInt( fileArray[2] );           

        var b = parseInt( fileArray[3] );           

        if ( l >= 0 && l <= 100 && a >= -128 && a <= 127 && b >= -128 && b <= 127 ) {

            var lab = new LabColor();

            lab.l = l, lab.a = a, lab.b = b;

            doc.selection.fill( lab, ColorBlendMode.NORMAL, 100, false );

            var saveFile = File( saveFolder.fsName + '/' + n );

            doc.saveAs( saveFile, opts, false, Extension.LOWERCASE );     

        } else {    

            //writelog()    

        };

    };

    doc.close( SaveOptions.DONOTSAVECHANGES );

    app.preferences.rulerUnits = userUnits;

};

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;

};