Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Bypass layer as Null object

  • Bypass layer as Null object

  • Ralph Moreau

    September 14, 2021 at 4:15 pm

    Hello all,

    I’m making a script that can detect a layer and it’s properties, then spit the location back out ; so that I may add some interpolation to it. Excuse the hacky way that I go about it. It mainly gets the job done until it has to iterate through the layers within a for loop. Within the for loop it’s saying layer is null. I use a method “eval” to try and run the interpolation. I placed an If statement to try and catch the null layer. It does it’s job, but now the function dosen’t work because the if statement ignores all layers. Would love some aid on this – thanks :

    ar comp = app.project.activeItem; // active comp

    if (comp instanceof CompItem) {

    var selectedProperties = comp.selectedProperties;

    var property = selectedProperties[0];

    var amLay = app.project.activeItem.layers.length;

    var comp = app.project.activeItem;

    var layers = comp.selectedLayers;

    var layer = layers[0];

    var selectedProperties = comp.selectedProperties;

    var property = selectedProperties[0];

    var propPath = getPropPath(property);

    var prop = eval(“layer.property” + getPropPath(property));


    function getPropPath(prop) {

    var layerRoot = false;

    var propPath = “”;

    while (prop.parentProperty) {

    propPath = “(‘” + prop.name + “‘)” + propPath;

    prop = prop.parentProperty;

    }

    return propPath;

    }

    function easeLayer() {

    for (var a = 1; a <= amLay; a++) {

    //~ if (proEx == null) continue; this is the if statement that dismantles the function

    var proEx = eval(“app.project.activeItem.layer(” + a + “)” + propPath + “.setInterpolationTypeAtKey(1,KeyframeInterpolationType.HOLD);”);

    }

    };

    easeLayer();

    };

  • Dan Ebberts

    September 14, 2021 at 4:29 pm

    I’m not sure the eval() stuff you’re doing is necessary, but to your specific question–try this:

    if (app.project.activeItem.layer(a).nullLayer) continue;
  • Ralph Moreau

    September 14, 2021 at 6:04 pm

    Thanks Dan. Your alternative makes sense in that I’d be referencing the path directly. But my code is a bit cumbersome. I need eval() to convert my strings into JavaScript expressions. And it does perfectly. But what happens is it pulls the eval() statement into a separate scope away from everything. And it doesn’t even get to listen to the if conditional.

    In extendscript it actually forces a new window open, placing the new ‘string’ as a JavaScript statement, evading the if conditional. I’ll have to figure another way. Thank you!

Viewing 1 - 3 of 3 posts

Log in to reply.

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