Skip to main content
Tomas Sinkunas
Legend
March 1, 2015
Question

Check if "Layer Styles" exist

  • March 1, 2015
  • 1 reply
  • 836 views

Hi guys.

How to check if layer has Layer Styles on it? By default, when you create a new layer, it does not have Layer Styles on it. However, when running this code:

    var myComp = app.project.activeItem;

    var myLayer = myComp.selectedLayers[0];

    for (var a = 1; a <= myLayer.numProperties; a++) {

        if (myLayer.property(a).matchName == "ADBE Layer Styles") {

            alert("ADBE Layer Styles is enabled: " + myLayer.property(a).enabled);

        }

    }

is return True, even though it does not have Layer Styles on It. However, if you add Drop Shadow or Inner Shadow etc it will also return true. BUT if you turn eye icon off, it will return FALSE.

Thank you.

This topic has been closed for replies.

1 reply

UQg
Legend
March 1, 2015

Try using .canSetEnabled


var p = myLayer.property("ADBE Layer Styles");

p.canSetEnabled;                               // if true, layer styles are visible and can be modified by script

p.canSetEnabled && p.enabled;     // // if true, layer styles are visible and are enabled, etc


As smallpath pointed out in this thread (Re: How to add mask reference in effect's Composition Options with After Effects CC 2014?), the canSomething attributes are not always reliable, but for layer styles normallly it works.

Xavier.

Tomas Sinkunas
Legend
March 1, 2015

Thanks UQj, but I am working with shape layers, and I am looping through all properties to check if they exists. By default shape layers have only 2 visible properties: that is "Content" and "Transform". However, all paths are stored in "Contents" property, and "Contents" will always return .canSetEnabled false, because it does not have that eye icon. So .canSetEnabled does not really work in my case.

UQg
Legend
March 1, 2015

Well, you asked for layer styles...

if you want to to know for a generic group whether it is visible or not, you will need several kinds of tests.

For an indexed group like .content, numProperties>0 should be enough (depending on what you need to do).

For transform, (it is always visible unless the layer is an ambient light or an audio only layer), a possible test would be:

     myGroup.position.dimensionSeparated ? myGroup.xPosition.canSetExpression : myGroup.position.canSetExpression;

For other named groups you'll need to check something else. Case by case i'm afraid.

Xavier.