ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Skipping Hidden Properties with ExtendScript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Keenan Parry
Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 5:17:42 pm
Last Edited By Keenan Parry on Oct 2, 2019 at 5:20:23 pm

Hey there, I have this script that scrubs through the active comp and automatically enables all expressions that are disabled in the comp. This works great until the composition has "Hidden Properties" and it gives me an error. Basically any effect like Grid or a Light Layer that will hide properties that are being unused. Those stop the script dead in its tracks and I'd like to make a Try Catch to simply skip these properties and move onto the next one. However, I'm having trouble implementing this as I'm new to extendscript. I've seen things like PropertyValueType.NO_VALUE or CUSTOM_VALUE, but I'm kinda lost on how to get this to work. Any help is appreciated!

(function() {
function recursiveDisableExpressions(propertyGroup) {
for (var i = 1; i &lt;= propertyGroup.numProperties; i++) {
var property = propertyGroup.property(i);

if (property instanceof PropertyGroup) {
recursiveDisableExpressions(property);
continue;
}

if (!property.canSetExpression) {
continue;
}

if (!property.isModified) {
continue;
}

if (property.expressionEnabled === false) {
property.expressionEnabled = true;
}
}
}

app.beginUndoGroup("Disable All Comp Expressions");

var comp = app.project.activeItem;

for (var i = 1; i &lt;= comp.numLayers; i++) {
var layer = comp.layer(i);

recursiveDisableExpressions(layer);
}

app.endUndoGroup();
})();


Return to posts index

Dan Ebberts
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 5:57:38 pm

Can you give a specific example of how to set up something that will generate an error?

Dan



Return to posts index

Keenan Parry
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 6:18:33 pm
Last Edited By Keenan Parry on Oct 2, 2019 at 6:20:14 pm

Hi Dan, thanks for the reply. It wasn't as easy to explain as I thought, so I made a little demo AEP file for you if you're willing to take the time. I set it up as easy and straightforward as possible.

https://www.dropbox.com/s/o7dj152x0uafvs8/Error_Demo.aep?dl=0

If you open that file you will see 3 layers. The layer in question that's causing the problem is the Grid effect on the layer called ERROR I believe? Possibly the grayed out Width and Height section? When you run the script, you will see the error pop up and after you stop the script, you will notice that it does actually enable the first two expressions but stops before it can enable the 3rd at the bottom.


Return to posts index


Dan Ebberts
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 6:23:43 pm

Ah, thanks.

Just adding a try/catch worked for me:


try{
property.expressionEnabled = true;
}catch (e){
}


Dan



Return to posts index

Keenan Parry
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 6:28:31 pm

Thanks Dan! Do you mind showing me where you put it in the full script? I attempted to put it in front of all the if statements and then after but I'm still getting the error.


Return to posts index

Dan Ebberts
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 6:31:01 pm


(function() {
function recursiveDisableExpressions(propertyGroup) {
for (var i = 1; i <= propertyGroup.numProperties; i++) {
var property = propertyGroup.property(i);

if (property instanceof PropertyGroup) {
recursiveDisableExpressions(property);
continue;
}

if (!property.canSetExpression) {
continue;
}

if (!property.isModified) {
continue;
}

if (property.expressionEnabled === false) {
try{
property.expressionEnabled = true;
}catch (e){
}
}
}
}

app.beginUndoGroup("Disable All Comp Expressions");

var comp = app.project.activeItem;

for (var i = 1; i <= comp.numLayers; i++) {
var layer = comp.layer(i);

recursiveDisableExpressions(layer);
}

app.endUndoGroup();
})();




Return to posts index


Keenan Parry
Re: Skipping Hidden Properties with ExtendScript
on Oct 2, 2019 at 6:34:01 pm

Once again, you have helped me directly as much as you have helped me indirectly. Thank you sir.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]