Copy link to clipboard
Copied
Hi, I'm just starting out with scripting photoshop and what I'm trying to achieve right now is to write a script that iterates over all the layers and turns off smart filters if they have them.
I figured out how to show and hide the filters using the ScriptListener but there's an error when I do that to a layer that doesn't have a smart filter on it.
So how would I go about determining if whether there are any smart filters applied?
function hasSmartFilter(){
var res = false;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID("smartObject"))){
desc = desc.getObjectValue(stringIDToTypeID("smartObject"));
if(desc.hasKey(stringIDToTypeID("filterFX"))) res = true;
}
return res;
};
Copy link to clipboard
Copied
function hasSmartFilter(){
var res = false;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID("smartObject"))){
desc = desc.getObjectValue(stringIDToTypeID("smartObject"));
if(desc.hasKey(stringIDToTypeID("filterFX"))) res = true;
}
return res;
};
Copy link to clipboard
Copied
Thanks.
Could you please also tell me how I determine if it's visible or not?
Also I'd appreciate some sort of reference on how I can figure these things out myself.
Copy link to clipboard
Copied
Other than what little there is in the scripting guide I don't think there is a reference or documentation on using Action Manager.
I have not found a way to determine if a smart filter is visible( enabled ). There are two ways you can enable/disable a smart filter. One way is effects all smart filters in the layer. The other effects only a specific filter.
I have code that can determine is a specific filter is enabled. But even if it is enabled whether is 'shows' or not is determined by the 'all filters enabled' setting. And I have not found a way to determine that master setting. So the code for a specific filter could say the filter is enabled when it is not because of the master setting.
Copy link to clipboard
Copied
Hmm, and would enabling the specific filter also enable the master setting?
What I'd like to do is have a checkbox in a dialog that toggles the SmartFilters on all the layers in the document (specifically all the blurs but all the filters would suffice).
My plan was to iterate over all the layers, store the state of the SmaterFilters in some sort of array (haven't gotten to that yet) and then hide them, and later when the checkbox is unchecked unhide them according to the states in the array.
Copy link to clipboard
Copied
Hmm, and would enabling the specific filter also enable the master setting?
Yes and without a way to get the current master setting you run the risk of changing the current setting.
It would be easy to disable all smart filters in a document. It would also be easy to enable all smart filters. The problem is you can not determine the current state of the filter so you can not restore to the pervious condition.
You might be able to come up with something using historyStates or snapshots but I think it would be very fragile.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now