c.pfaffenbichler I want to thank you so much for taking your time out to help me. I can't tell you how easy you've made this job for me. I'm so grateful for your kind help, thank you!!
| // select files and place in a selected smart object; |
| // to cause the so in the so to be scaled to fit the |
resolution is temprarily changed, but this is no guarantee for
this to happen;
| // 2015, use it at your own risk; |
| #target photoshop |
| if (app.documents.length > 0) { |
| var myDocument = app.activeDocument; |
| var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1]; |
| var thePath = myDocument.path; |
| var theLayer = myDocument.activeLayer; |
| // psd options; |
| psdOpts = new PhotoshopSaveOptions(); |
| psdOpts.embedColorProfile = true; |
| psdOpts.alphaChannels = true; |
| psdOpts.layers = true; |
| psdOpts.spotColors = true; |
| // check if layer is smart object; |
| if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert |
("selected layer is not a smart object")}
| else { |
| if ($.os.search(/windows/i) != -1) {var theFiles = |
File.openDialog ("please select files",
"*.pdf;*.ai;*.psd;*.tif;*.png", true)}
| else {var theFiles = File.openDialog ("please select |
files", getFiles, true)};
| if (theFiles) { |
| // set to pixels; |
| var originalRulerUnits = app.preferences.rulerUnits; |
| app.preferences.rulerUnits = Units.PIXELS; |
| // get bounds; |
| var theBounds = theLayer.bounds; |
| // work through the array; |
| for (var m = 0; m < theFiles.length; m++) { |
| var theNewName = File(theFiles).name.match(/(.*)\.[^ |
\.]+$/)[1];
| // replace smart object; |
| placeSmartObjectInSmartObject |
(app.activeDocument.activeLayer, theFiles);
| | #target photoshop |
| function main(){ |
| | if(!documents.length) return; |
| | var doc = activeDocument; |
| | var oldPath = activeDocument.path; |
| | for(var a=0;a<doc.layerSets.length;a++){ |
| | activeDocument.activeLayer = |
activeDocument.layers.getByName(doc.layerSets.name);
| | dupLayers(); |
| | activeDocument.mergeVisibleLayers(); |
| | activeDocument.trim |
(TrimType.TRANSPARENT,true,true,true,true);
var saveFile= File(oldPath+"/PRE-NAME"+theNewName
+"-"+doc.layerSets.name +".jpg");
saveJPG(saveFile,10);
(SaveOptions.DONOTSAVECHANGES);
| | } |
| } |
| main(); |
| | |
| | |
| function dupLayers() { |
| | var desc143 = new ActionDescriptor(); |
| | var ref73 = new ActionReference(); |
| | ref73.putClass( charIDToTypeID('Dcmn') ); |
| | desc143.putReference( charIDToTypeID('null'), ref73 ); |
| | desc143.putString( charIDToTypeID('Nm '), |
activeDocument.activeLayer.name );
| | var ref74 = new ActionReference(); |
| | ref74.putEnumerated( charIDToTypeID('Lyr '), |
charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
| | desc143.putReference( charIDToTypeID('Usng'), ref74 ); |
| | executeAction( charIDToTypeID('Mk '), desc143, |
DialogModes.NO );
| } |
| | |
| | |
| function saveJPG(saveFile, jpegQuality) { |
| | app.activeDocument.flatten(); |
| | jpgSaveOptions = new JPEGSaveOptions(); |
| | jpgSaveOptions.embedColorProfile = true; |
| | jpgSaveOptions.formatOptions = |
FormatOptions.STANDARDBASELINE;
| | jpgSaveOptions.matte = MatteType.NONE; |
| | jpgSaveOptions.quality = jpegQuality; //1-12 |
| | activeDocument.saveAs(saveFile, jpgSaveOptions, |
true,Extension.LOWERCASE);
// undo;
myDocument.activeHistoryState = myDocument.historyStates
[myDocument.historyStates.length-2]
};
// reset;
originalRulerUnits = app.preferences.rulerUnits;
}
}
};
| ////// open smart object ////// |
| function placeSmartObjectInSmartObject (theLayer, thisFile) |
{
| if (theLayer.kind == "LayerKind.SMARTOBJECT") { |
| // get prefernces setting; |
| var ref = new ActionReference(); |
| ref.putProperty(stringIDToTypeID("property"), |
stringIDToTypeID("generalPreferences"));
| ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID |
("Ordn"), charIDToTypeID("Trgt") );
| var applicationDesc = executeActionGet(ref); |
| var generalDesc = applicationDesc.getObjectValue |
(stringIDToTypeID("generalPreferences"));
| var resizeDuringPlace = generalDesc.getBoolean |
(stringIDToTypeID("resizePastePlace"));
| if (resizeDuringPlace == false) { |
| // ======================================================= |
| var idsetd = charIDToTypeID( "setd" ); |
| | var desc1 = new ActionDescriptor(); |
| | var idnull = charIDToTypeID( "null" ); |
| | var ref1 = new ActionReference(); |
| | var idPrpr = charIDToTypeID( "Prpr" ); |
| | var idGnrP = charIDToTypeID( "GnrP" ); |
| | ref1.putProperty( idPrpr, idGnrP ); |
| | var idcapp = charIDToTypeID( "capp" ); |
| | var idOrdn = charIDToTypeID( "Ordn" ); |
| | var idTrgt = charIDToTypeID( "Trgt" ); |
| | ref1.putEnumerated( idcapp, idOrdn, idTrgt ); |
| | desc1.putReference( idnull, ref1 ); |
| | var idT = charIDToTypeID( "T " ); |
| | var desc2 = new ActionDescriptor(); |
| | var idresizePastePlace = stringIDToTypeID( |
"resizePastePlace" );
| | desc2.putBoolean( idresizePastePlace, true ); |
| | var idlegacyPathDrag = stringIDToTypeID( |
"legacyPathDrag" );
| | desc2.putBoolean( idlegacyPathDrag, true ); |
| | var idGnrP = charIDToTypeID( "GnrP" ); |
| | desc1.putObject( idT, idGnrP, desc2 ); |
| executeAction( idsetd, desc1, DialogModes.NO ); |
| }; |
| // ======================================================= |
| var idplacedLayerEditContents = stringIDToTypeID( |
"placedLayerEditContents" );
| | var desc2 = new ActionDescriptor(); |
| executeAction( idplacedLayerEditContents, desc2, |
DialogModes.NO );
| // set to high resolution to make scaling on placing |
probable;
| var theResolution = activeDocument.resolution; |
| activeDocument.resizeImage(undefined, undefined, 3000, |
ResampleMethod.NONE);
| // place so; |
| // ======================================================= |
| var idPlc = charIDToTypeID( "Plc " ); |
| | var desc4 = new ActionDescriptor(); |
| | var idAs = charIDToTypeID( "As " ); |
| | var desc5 = new ActionDescriptor(); |
| | var idfsel = charIDToTypeID( "fsel" ); |
| | var idpdfSelection = stringIDToTypeID( |
"pdfSelection" );
| | var idpage = stringIDToTypeID( "page" ); |
| | desc5.putEnumerated( idfsel, idpdfSelection, idpage |
);
| | var idPgNm = charIDToTypeID( "PgNm" ); |
| | desc5.putInteger( idPgNm, 1 ); |
| | var idCrop = charIDToTypeID( "Crop" ); |
| | var idcropTo = stringIDToTypeID( "cropTo" ); |
| | var idtrimBox = stringIDToTypeID( "trimBox" ); |
| | desc5.putEnumerated( idCrop, idcropTo, idtrimBox ); |
| | var idPDFG = charIDToTypeID( "PDFG" ); |
| | desc4.putObject( idAs, idPDFG, desc5 ); |
| | var idnull = charIDToTypeID( "null" ); |
| | desc4.putPath( idnull, new File( thisFile ) ); |
| | var idFTcs = charIDToTypeID( "FTcs" ); |
| | var idQCSt = charIDToTypeID( "QCSt" ); |
| | var idQcsa = charIDToTypeID( "Qcsa" ); |
| | desc4.putEnumerated( idFTcs, idQCSt, idQcsa ); |
| | var idOfst = charIDToTypeID( "Ofst" ); |
| | var desc6 = new ActionDescriptor(); |
| | var idHrzn = charIDToTypeID( "Hrzn" ); |
| | var idRlt = charIDToTypeID( "#Rlt" ); |
| | desc6.putUnitDouble( idHrzn, idRlt, 0.000000 ); |
| | var idVrtc = charIDToTypeID( "Vrtc" ); |
| | var idRlt = charIDToTypeID( "#Rlt" ); |
| | desc6.putUnitDouble( idVrtc, idRlt, 0.000000 ); |
| | var idOfst = charIDToTypeID( "Ofst" ); |
| | desc4.putObject( idOfst, idOfst, desc6 ); |
| | var idAntA = charIDToTypeID( "AntA" ); |
| | desc4.putBoolean( idAntA, true ); |
| executeAction( idPlc, desc4, DialogModes.NO ); |
| // toggle visibility of others; |
| // ======================================================= |
| var idShw = charIDToTypeID( "Shw " ); |
| | var desc10 = new ActionDescriptor(); |
| | var idnull = charIDToTypeID( "null" ); |
| | var list4 = new ActionList(); |
| | var ref7 = new ActionReference(); |
| | var idLyr = charIDToTypeID( "Lyr " ); |
| | var idOrdn = charIDToTypeID( "Ordn" ); |
| | var idTrgt = charIDToTypeID( "Trgt" ); |
| | ref7.putEnumerated( idLyr, idOrdn, idTrgt ); |
| | list4.putReference( ref7 ); |
| | desc10.putList( idnull, list4 ); |
| | var idTglO = charIDToTypeID( "TglO" ); |
| | desc10.putBoolean( idTglO, true ); |
| executeAction( idShw, desc10, DialogModes.NO ); |
| // reset resolution; |
| activeDocument.resizeImage(undefined, undefined, |
theResolution, ResampleMethod.NONE);
| // close; |
| app.activeDocument.close(SaveOptions.SAVECHANGES) |
| }; |
| }; |
| ////// get psds, tifs and jpgs from files ////// |
| function getFiles (theFile) { |
| if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) { |
| return true |
| }; |
| }; |