Here's something I whipped up. It doesn't pay attention to size, or location, so if the things you are replacing the smart object with are of differing sizes, that would need to be addressed. Also, grab this PDF and you can look at what can be set for save for web options:
http://wwwimages.adobe.com/content/dam/ ... pt-ref.pdf
I don't claim to be great at this, so there may be a better way to do it. All I can say is that when I tested it with conditions that I think will closely line up with your own, it worked for me.
One other thing to be aware of, the name of the saved file is whatever the smart object replacement file is named. If they aren't unique, you'll run into an issue.
Code: Select all
#target Photoshop
var docRef=app.activeDocument
var smartObject
saveForWebOpts=new ExportOptionsSaveForWeb//check PDF mentioned in post for what you can set here
function replaceSmartObject(){
var selectedFolder= Folder.selectDialog('Please select the folder containing files for smart object replacement:', Folder('~/Desktop'))//loads your desktop, asks you to point out the files you want to be used as smart objects
var outputFolder= Folder.selectDialog('Please select the folder where files should be saved', Folder('~/Desktop'))//loads your desktop, askss you to select a location so save the files
var fileList = selectedFolder.getFiles("*.jpg");//limit file types used by putting them in the ()
for (b=0;b<fileList.length;b++){
var saveName=fileList[b].name
for (a=0;a<docRef.artLayers.length;a++){//this only looks at top level layers, if you have groups that need to be looked in, they have to be gone through differently
if (docRef.artLayers[a].kind==LayerKind.SMARTOBJECT){
smartObject=docRef.artLayers[a]
}
docRef.activeLayer=smartObject//makes your active layer the smart object
replaceContents ()
function replaceContents(smartObject){//script listener code to replace the contents of the smart object, as I don't think this is accessible without it
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc403 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc403.putPath( idnull, new File( fileList[b] ) );
executeAction( idplacedLayerReplaceContents, desc403, DialogModes.NO );
}
var saveFile=File(outputFolder + '/' + saveName)
docRef.exportDocument (saveFile, ExportType.SAVEFORWEB, saveForWebOpts)//this seems really slow, you may want to try using script listener to see if you get better results
}
}
}
replaceSmartObject()//run the script