Skip to main content
Inspiring
August 26, 2013
Answered

Checking if layer has smart filters

  • August 26, 2013
  • 1 reply
  • 1167 views

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?

This topic has been closed for replies.
Correct answer Michael_L_Hale

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;

};

1 reply

Michael_L_HaleCorrect answer
Inspiring
August 26, 2013

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;

};

EnsilZahAuthor
Inspiring
August 27, 2013

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.

Inspiring
August 27, 2013

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.