Skip to main content
Known Participant
November 13, 2012
Answered

how to "save for web" with dataset information

  • November 13, 2012
  • 1 reply
  • 1561 views

I have created web page design psd set up with a main image.  The main image is defined as a pixel replacement variable and uses a dataset to load in images from a local folder.  I have over 100 images in this folder and I need to resize the image to 250 pixels wide and "save for web".   The resizing and saving is easily done with an action but the trick comes that I need to use another column in my dataset as the saved files name.

Is it possible to create an action that will loop through each row in my dataset, do the pixel replacement on the image, grab the filename from the next column, flatten & resize the image and then save it as the filename?  Of course, it would then need to undo the flattening and resizing to start at the next row.

I guess I could break it into two actions.  One that will read the dataset, do the pixel replacement and export for web with the new filename.  Then I could set up a second action to run in batch on the folder that contains the recently exported images and just resize all of them.

What I'm not sure how to do (if it's even possible) is to loop through the dataset with an action, get the variable from the dataset for the filename and export for web with that name.  Any ideas?  Thanks.

This topic has been closed for replies.
Correct answer Michael_L_Hale

Thanks for the offer Michael.  I have been able to get the process working here but there are a few steps to it.  Obviously it would be nice if it was all consolidated into one script.  Would you mind sharing whatever you think might be helpful here?  If you'd like to email my email is gswartz at synergydatasystems dot com  Thanks!


Here are some function I use. With these function you can import a dataset csv file to your document. Get the dataSets names form the csv. Then in a loop apply a dataSet by name then saveAs in any format you like. The loop repeats until all the dataSets have be processed.

 

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 );
};
function applyDataSet(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 );
};
function getDataSetNames(csvFileRef) { 
    _ftn = function(string){ 
    var csvItems = string.split(","); 
    datasetName = csvItems[0]       
    return datasetName; 
};
csvFileRef.open(); 
var datasetArray = new Array(); 
var i = 0;// assumes the dataSet name is the first field
while (csvString = csvFileRef.readln()) { 
   if (csvString.length < 2) continue; // Skip empty lines 
  datasetArray[i] = _ftn(csvString); 
  i++; 
} 
csvFileRef.close(); 
return datasetArray; 
} 
//sample usage 
var csvFileRef = File.openDialog("Please select CSV file"); 
var datasetNames = getDataSetNames(csvFileRef); 
alert(datasetNames.length-1);//number of data sets 
alert(datasetNames[1]);// first data set name

 

1 reply

vtxr1300Author
Known Participant
November 13, 2012

Well I guess I should have read a few more tutorials before posting this.  Although I can't get the id from my dataset to save the image I can export the entire dataset as separate psds under file>export.  By using the file naming options I can get far enough along that I can then create an action to run separately that will handle everything else.

Inspiring
November 14, 2012

I have some functions for working with datasets. If your export, batch sfw doesn't work as you expected let me know and I will post them.

vtxr1300Author
Known Participant
November 16, 2012

Thanks for the offer Michael.  I have been able to get the process working here but there are a few steps to it.  Obviously it would be nice if it was all consolidated into one script.  Would you mind sharing whatever you think might be helpful here?  If you'd like to email my email is gswartz at synergydatasystems dot com  Thanks!