1 Reply Latest reply on Apr 30, 2010 7:30 AM by Michael L Hale

    Using datasets

    flex_n00b

      Hi,

       

       

      In a photoshop dataset, I wish to do the following-

       

      1. save as .jpg

      2. name the file using a variable used in the document

       

      how can this be done? i am using cs4

        • 1. Re: Using datasets
          Michael L Hale Level 5

          Here is one way to save the sets as jpgs. It assumes that the activeDocument has datasets defined and uses the first fieldname in the dataset csv as the savename for the jpg.

           

          fileImportDataSets = function(file) { 
              var desc = new ActionDescriptor(); 
                  var ref = new ActionReference(); 
                  ref.putClass( stringIDToTypeID( "dataSetClass" ) ); 
              desc.putReference( charIDToTypeID( "null" ), ref ); 
              desc.putPath( charIDToTypeID( "Usng" ), new File( file ) ); 
              desc.putEnumerated( charIDToTypeID( "Encd" ), stringIDToTypeID( "dataSetEncoding" ), stringIDToTypeID( "dataSetEncodingAuto" ) ); 
              desc.putBoolean( stringIDToTypeID( "eraseAll" ), true ); 
              desc.putBoolean( stringIDToTypeID( "useFirstColumn" ), true ); 
          executeAction( stringIDToTypeID( "importDataSets" ), desc, DialogModes.NO ); 
          }
          applyDataSet = function(setName) { 
              var desc = new ActionDescriptor(); 
                  var setRef = new ActionReference(); 
                  setRef.putName( stringIDToTypeID( "dataSetClass" ), setName ); 
              desc.putReference( charIDToTypeID( "null" ), setRef ); 
          executeAction( charIDToTypeID( "Aply" ), desc, DialogModes.NO ); 
          }
          getDataSetNames = function(csvFileRef) {
               _ftn = function(string){
                    var csvItems = string.split(",");
                    datasetName = csvItems[0]          
                    return datasetName;
               }
               csvFileRef.open();
               var datasetArray = new Array();
               var i = 0;
               while (csvString = csvFileRef.readln()) {
                    if (csvString.length < 2) continue; // Skip empty lines
                 datasetArray[i] = _ftn(csvString);
                 i++;
               }
               csvFileRef.close();
               return datasetArray;
          }
          // jpeg options used for all the saves
          var jpgOptns = new JPEGSaveOptions();
               jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
               jpgOptns.embedColorProfile = true;
               jpgOptns.matte = MatteType.NONE;
               jpgOptns.quality = 8; 
          //prompt for file
          var csvFileRef = File.openDialog("Please select CSV file"); 
          fileImportDataSets(csvFileRef); //inport the CSV file into the template
          var datasetNames = getDataSetNames(csvFileRef);// set up the dataset array
          //setup a loop for your data set names 
          for (i=1; i < datasetNames.length; i++) {
               applyDataSet(datasetNames[i]); 
               //edit the file if needed 
               //save the file. Here I use testItem.contents of layer 'name' as the filename
               app.activeDocument.activeLayer = app.activeDocument.artLayers.getByName("name"); 
               jpgSaveFile = new File(csvFileRef.path + "/" + app.activeDocument.activeLayer.textItem.contents + ".jpg");
               app.activeDocument.saveAs (jpgSaveFile ,jpgOptns , true, Extension.LOWERCASE);
          }//loop to next data set