Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions ‘For’ Loop and Try/Catch Block

  • ‘For’ Loop and Try/Catch Block

    Posted by Tiago Cav on July 15, 2015 at 11:44 pm

    I use the effect Layer Control. But When set ‘None’ results in an error. I used a ‘For’ loop to collect the three effect used; So I want to associate the Try / Catch Block to prevent these errors. I try this expression, but no work. Thanks.

    // Variables
    var t=thisComp.layer("Less");
    var a=t.effect("Scale")("Layer").name;
    var b=t.effect("Position")("Layer").name;
    var c=t.effect("Side")("Layer").name;
    var e=["a","b","c"];
    // For Loop
    for (var i=0; i<e.length; i++){
    }
    // Try/Catch Block
    try{
    i;
    }catch(err){
    i=0;
    }

    Tiago Cav replied 10 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    July 16, 2015 at 12:45 am

    I’m not sure what you’re trying to do exactly, but this statement, for example:

    var a=t.effect(“Scale”)(“Layer”).name;

    will generate an error when the layer control is set to None. So you need to surround it with try/catch. The question is though, what do you put into variable a when this happens?


    try{
    var a = t.effect("Scale")("Layer").name;
    }catch(err){
    var a = ???
    }

    But do you really need the name of the layer selected by the control, or could you defer accessing the layer control until you need to get a value?

    Dan

  • Tiago Cav

    July 16, 2015 at 1:56 am

    Hey Dan, you have a good intuition.
    Same not knowing exactly what I wanted, by me not knowing express myself right, managed to give me the road that would lead to the right.
    So I was able.

    Thank You Very Much! Always very efficient.

    // This is the main part of where were the problem in expression.
    var a="Scale";
    var b="Position";
    var c="Side";
    var names=[a, b, c];
    for (var i=0; i<names.length; i++){
    try{
    var e = t.effect(names[i])("Layer").name;
    }catch(err){
    var e = 0;
    }
    }

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