6 Replies Latest reply on Nov 7, 2015 12:59 PM by atelje

    How to batch generate hundreds of color swatches?

    knotomek Level 1

      - 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)

        • 1. Re: How to batch generate hundreds of color swatches?
          c.pfaffenbichler Level 9

          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?

          • 2. Re: How to batch generate hundreds of color swatches?
            knotomek Level 1

            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
            • 3. Re: How to batch generate hundreds of color swatches?
              Muppet Mark Level 5

              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[i][0];     
                      var l = parseInt( fileArray[i][1] );      
                      var a = parseInt( fileArray[i][2] );            
                      var b = parseInt( fileArray[i][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;
              };
              
              • 4. Re: How to batch generate hundreds of color swatches?
                knotomek Level 1

                great,

                 

                yes it is one of many ways to do.

                thanks a lot.

                P.S. speed of swatches generating is amazing (439 swatches in 30 sec)

                • 5. Re: How to batch generate hundreds of color swatches?
                  knotomek Level 1

                  NOTE FOR THIS SCRIPT USERS

                  - name should not contain dots!

                  - replace the dots with underscores or other

                  • 6. Re: How to batch generate hundreds of color swatches?
                    atelje Level 1

                    Hello!

                     

                    I need also something like this "from CSV to Photoshop",

                    but instead of 439 files, it should be the only one final LAB TIF-LZW.

                     

                    90 colour swatches of size 28 x 20 px with 3 px gap should be arranged from left to right in 5 rows, 18 columns.

                    Mac OS 10.6.8, Photoshop CS6.

                     

                    Many thanks for your help!