Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Help Needed – Check if layer’s mask has keyframes in maskpath

  • Help Needed – Check if layer’s mask has keyframes in maskpath

  • Tom Pinnes

    January 10, 2021 at 12:18 pm

    Hello everyone, I am trying to create an error check button that finds and alerts about layers with no keyframes in their mask’s maskpath.

    This is my code so far-

    var project = app.project; /// Get project data

    var currentComp = project.activeItem; /// Get Active comp

    var allLayers = currentComp.layers; /// Get all layers – array

    var numOfLayers = allLayers.length; /// Gets length – integer

    var errorArray = []; /// Create an empty error array

    for(i=1;i<numOfLayers+1;i++) /// iterate through all layers

    {

    var currentLayer = allLayers[i]; /// Get layer from position i

    var myMask = currentLayer.mask(1);

    var myProp = myMask.maskPath;

    if(myProp .isTimeVarying==false)

    {

    errorArray.push(currentLayer.index);

    }

    }

    if(errorArray.length==0)

    {

    alert(“0 Layers with no keyframes”);

    }

    else

    {

    alert(“Layers #”+errorArray.toString()+” has no keyframes”,”Error”);

    }

    Sadly it isn’t working, I would love some help understanding where I got it wrong and also if there’s another way to do it.

    Thanks, Tom. 🙂

  • Dan Ebberts

    January 10, 2021 at 5:25 pm

    This seems to work:

    var currentComp = app.project.activeItem;

    var errorArray = [];

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

    if (currentComp.layer(i).property("ADBE Mask Parade").numProperties == 0){

    errorArray.push(i);

    }else{

    if(currentComp.layer(i).property("ADBE Mask Parade").property("ADBE Mask Atom").property("ADBE Mask Shape").numKeys == 0){

    errorArray.push(i);

    }

    }

    }

    if (errorArray.length == 0){

    alert("0 Layers with no keyframes");

    }else{

    for (var i = 0; i < errorArray.length; i++){

    alert("Layer #"+errorArray[i]+" has no keyframes","Error");

    }

    }

  • Tom Pinnes

    January 11, 2021 at 9:14 am

    Hey Dan thanks again for helping me out ! I have some questions regarding your code-

    1. In your for loop you wrote “var i =1” why is it different from “i=1” ? What types of error could’ve been produced ?

    2. Just wanted to make sure that i got this part right – “currentComp.layer(i).property(“ADBE Mask Parade”).numProperties == 0″ – The if statement is checking that the 1st index of a layer property (mask) exists ?

    3. I notice that i tend to store properties into vars when not needed, however i can’t wrap my head around the hierarchy in accessing different properties in 1 line as you did. I’m using https://after-effects-scripting-guide.readthedocs.io/ as my bible but i’m still very much confused, can you recommend another good source ?

    And once again thanks ! 🙂

  • Dan Ebberts

    January 11, 2021 at 4:19 pm

    1. If you don’t declare the i variable locally, JavaScript will create a global one for you. You’ll probably get away with it, but you could get into trouble if you already have one declared globally and you start using it locally to control your for loop.

    2. That’s just checking to see if the layer actually has any masks. My assumption was no masks = no keyframes, but you may want to handle that situation differently (just skip that layer maybe?)

    3. If you don’t already have Jeff Almasol’s incredibly useful rd_GimmePropPath.jsx script you should get it. I use it all the time to examine complex property hierarchies and get the match names for properties.

  • Tom Pinnes

    January 12, 2021 at 11:34 am

    1. Good to know.

    2.You are right to assume so, it works as intended now.

    3.That’s an amazing script! It’s exactly what I was looking for to learn properties and ways to access them.

    Thanks !

Viewing 1 - 5 of 5 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy