Adobe After Effects Expressions Forum
After Effects script to hide and show layer styles.
After Effects script to hide and show layer styles.
by Toms Burāns on Jul 5, 2017 at 4:03:10 pm

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!


Re: After Effects script to hide and show layer styles.
by Toms Burāns on Jul 7, 2017 at 12:52:17 pm

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);
}
}
}



Re: After Effects script to hide and show layer styles.
by Sebastian Rasche on Jul 10, 2017 at 1:18:01 pm

How exactly do you use this? I copied the code into a .jsx file and executed it but nothing happens.
Also tried the code inside ft-toolbar but to no success. Thanks!


Re: After Effects script to hide and show layer styles.
by Toms Burāns on Jul 10, 2017 at 1:52:16 pm

Just looked at the code again. Looks like creative cow post editor turned "<" into "& lt ;" . That's probably the reason why its not working for you. Fix this line -
for (var i = 1; i <= curComp.layers.length; i++) {


Re: After Effects script to hide and show layer styles.
by Sebastian Rasche on Jul 10, 2017 at 2:01:22 pm

awesome! it works now and is sitting perfectly within my ft-toolbar. Thanks!


Re: After Effects script to hide and show layer styles.
by Sebastian Rasche on Jul 10, 2017 at 1:21:52 pm

How exactly do I use this script?


Re: After Effects script to hide and show layer styles.
by luis palencia on Apr 19, 2018 at 7:18:57 pm

I run the script and show me this: "Unable to execute script at line 13. undefined is not an object"


Re: After Effects script to hide and show layer styles.
by maximus darringer on May 5, 2019 at 11:22:00 am

Perfect Thanks!!





© CreativeCOW.net