Skip to main content
tomsb85336751
Participant
July 7, 2017
Answered

Script to hide and show layer styles.

  • July 7, 2017
  • 1 reply
  • 2532 views

Hi! I have a rather complex character rig with many nested compositions and a lot of expressions to drive it. Almost all layers that make up the character have some layer styles applied. (inner shadow, inner glow etc). The thing is, the rig is starting to get very slow and laggy. When I disable the layer styles it moves a lot faster but turning them on and off one by one is not ideal. Could this be done with a script? Ideally, it would disable/enable all layer styles in the current comp as well as in all nested comps inside it. I don't have any experience with scripts, only expressions. Any help is greatly appreciated!

This topic has been closed for replies.
Correct answer tomsb85336751

Managed to do this myself.

This script toggles layer styles on and off for all layers in the currently active composition as well as in all compositions nested inside it.

var activeComp = app.project.activeItem;

if (activeComp == null) {

    alert("Select a composition.");

} else {

    toggleLayerStyles(activeComp);

}

function toggleLayerStyles(curComp) {

    for (var i = 1; i <= curComp.layers.length; i++) {

        curL = curComp.layer(i);

        if (curL.layerStyle.canSetEnabled == true) {

            if (curL.layerStyle.enabled == true) {

                curL.layerStyle.enabled = false;

            } else {

                curL.layerStyle.enabled = true;

            }

        }

        if (curL.source instanceof CompItem) {

            toggleLayerStyles(curL.source);

        }

    }

}

1 reply

tomsb85336751
tomsb85336751AuthorCorrect answer
Participant
July 7, 2017

Managed to do this myself.

This script toggles layer styles on and off for all layers in the currently active composition as well as in all compositions nested inside it.

var activeComp = app.project.activeItem;

if (activeComp == null) {

    alert("Select a composition.");

} else {

    toggleLayerStyles(activeComp);

}

function toggleLayerStyles(curComp) {

    for (var i = 1; i <= curComp.layers.length; i++) {

        curL = curComp.layer(i);

        if (curL.layerStyle.canSetEnabled == true) {

            if (curL.layerStyle.enabled == true) {

                curL.layerStyle.enabled = false;

            } else {

                curL.layerStyle.enabled = true;

            }

        }

        if (curL.source instanceof CompItem) {

            toggleLayerStyles(curL.source);

        }

    }

}

Participant
April 7, 2021

Your a saint! Thank you so much for this