Copy link to clipboard
Copied
This script takes the last filter that was applied and repeats it on all selected layers and masks. (It is designed to avoid the need to collapse layers into a smart object in order to batch-apply filters).
However, there's a bug in it that I can't figure out: it works beautifully for something like Gaussian Blur, but for Liquify, it records in the history that the filter has been applied, yet the layers remain untouched.
Steps to reproduce: 1. Blur layer 1. 2. Select layers 2 (masked) & 3 (unmasked) 3. Run script 4. Repeat 1-3 but with liquify instead of blur.
____________________
#target photoshop var defaultRulerUnits = preferences.rulerUnits; preferences.rulerUnits = Units.PIXELS; var doc = app.activeDocument; var layers = doc.layers; var typeArray = new Array (); var isim = new Array();cTID = function(s) { return app.charIDToTypeID(s); }; sTID = function(s) { return app.stringIDToTypeID(s); }; function repeatlastfilter() { runMenuItem(cTID("LstF"), true); } function checklayermask() { try { Select_Layermask(); } catch (err) { return } repeatlastfilter(); Select_Original_Layer(); } // MAIN function main() { app.bringToFront(); var SelectedLayers = getSelectedLayers(); for (var i = 0; i < SelectedLayers.length; i++) { doc.activeLayer = SelectedLayers[i]; isim[i] = SelectedLayers[i].name; //selectlayer(isim[i]); //alert (isim[i]);
repeatlastfilter();
checklayermask(); //doAction(DDActions.selection.text, DDActionSet.selection.text); } } // SELECT ORIGINAL LAYER function Select_Original_Layer(enabled, withDialog) { if (enabled != undefined && !enabled) return; var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO); var desc1 = new ActionDescriptor(); var ref1 = new ActionReference(); ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), sTID("RGB")); desc1.putReference(cTID('null'), ref1); desc1.putBoolean(cTID('MkVs'), false); executeAction(cTID('slct'), desc1, dialogMode); }; // SELECT LAYER MASK function Select_Layermask(enabled, withDialog) { if (enabled != undefined && !enabled) return; var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO); var desc1 = new ActionDescriptor(); var ref1 = new ActionReference(); ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk ')); desc1.putReference(cTID('null'), ref1); desc1.putBoolean(cTID('MkVs'), false); executeAction(cTID('slct'), desc1, dialogMode); }; // GET SELECTED LAYERS function getSelectedLayers() { var resultLayers=new Array(); try{ var descGrp = new ActionDescriptor(); var refGrp = new ActionReference(); refGrp.putEnumerated(cTID( "Lyr " ),cTID( "Ordn" ),cTID( "Trgt" )); descGrp.putReference(cTID( "null" ), refGrp ); executeAction( sTID( "groupLayersEvent" ), descGrp, DialogModes.NO ); for (var ix=0;ix<app.activeDocument.activeLayer.layers.length;ix++){resultLayers.push(app.activeDocument.activeLayer.layers[ix])} var desc5 = new ActionDescriptor(); var ref2 = new ActionReference(); ref2.putEnumerated( cTID( "HstS" ), cTID( "Ordn" ), cTID( "Prvs" ) ); desc5.putReference( cTID( "null" ), ref2 ); executeAction( cTID( "slct" ), desc5, DialogModes.NO ); } catch (err) { } return resultLayers; } main();
Copy link to clipboard
Copied
runMenuItem(cTID("LstF"), true);
Seems to work fine. It would fails if a filter has not been used yet in the current Photoshop Session. And the last filter can fail if an inappropriate layer is current.
However in the script you posted it look like it will not be executed its comment out in main
Copy link to clipboard
Copied
Thanks for your reply. It looks like it was commented out but that was just a quirk of the copy/paste into this dialogue box unfortunately. I've edited the question now.
Were you able to make it work?
Copy link to clipboard
Copied
I wrote"runMenuItem(cTID("LstF"), true);
Seems to work fine. It would fails if a filter has not been used yet in the current Photoshop Session. And the last filter can fail if an inappropriate layer is current."
In other words the Script may work the script may or may not work. It depends on condition. The only thing the script catches is a layer not having a layer mask. The use of the two functions were comment out so I did not the two functions. I just checked to see if run menu item last filter works. And saw it would not be available if a filter has not need use in the Photoshop session and that if the filter was inappropriate for the layer the filter would fail. The script is not coded to tolerate failure in the functions.
Copy link to clipboard
Copied
executeAction(charIDToTypeID("LqFy"), undefined, DialogModes.NO);