Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Problem with repeating expression (for checking if layer exists)

  • Problem with repeating expression (for checking if layer exists)

    Posted by Felix Weber on October 23, 2015 at 3:41 pm

    Hi there,

    I have a problem with the repeating of an expression.

    What I want to accomplish (The expression is on a slider).

    For every Layer (in another Comp)
    1. Check if layer(name”n”) exists
      2.1 If yes
        2.1.1 Check for 2 attributes of layer(name”n”)
        2.1.2 Add .xPosition from layer(name”n”) to slider
        2.1.3 Repeat from 1. with “n+1”
      2.2 If not, repeat from 1. with “n+1”

    I have part 1. to 2.1.2, but I can’t get my expression repeating the steps 🙁
    Any suggestions on how to do this?

    A big thank you in advance from Germany,
    Felix

    I entered the what I already have below:

    n = 1

    try{
    L = comp("compname").layer("layername " + n);
    exists = true;
    }catch (err){
    exists = false;
    }

    if (exists){

    if ((comp("compname").layer("layername " + n) != null) && (comp("compname").layer("layername " + n).opacity > 0 ))
    {comp("compname").layer("layername " + n).effect("Einstellungen für Schieberegler")("Schieberegler")}
    else
    {value}

    }else{
    {value}
    }

    Felix Weber replied 10 years, 10 months ago 2 Members · 4 Replies
  • 4 Replies
  • Xavier Gomez

    October 25, 2015 at 3:16 pm

    This ?

    theComp = comp("compname");
    N = theComp.numLayers;
    val = value; // the prexpression value of the current property (slider)

    for (n=1; n<=N; n++){ try{ L=theComp.layer("layername" + n); if (L.transform.opacity>0 && L.effect("Einstellungen für Schieberegler")("Schieberegler").value){ // increment the slider value val += L.transform.position.value[0]; }; // else do nothing } catch(e){ // ignore (the layer does not exist, or the effect "Einstellungen für Schieberegler" does not exist) }; }; // final result: val;

  • Felix Weber

    October 26, 2015 at 10:01 am

    Awesome! That was exactly what I needed. Thank you so much 🙂

    But the code caused another problem.

    To change the position of the null layer (with the slider from above added, now called “Schieberegler”) I need to cycle through all the previous frames in order to find the starting time for my ease.

    I used Dan’s expression from Motionscript.com. It kind of works, but with more than 3 objects, it says “Timeout while waiting for the engine”.

    My thought on solving this is to only let it check for the trigger event between now (time) and the last trigger event.
    How do I add that to the expression?

    threshold = 1650;

    P = effect("Einstellungen für Schieberegler")("Schieberegler");

    above = false;
    frame = Math.round(time / thisComp.frameDuration);
    while (true){
    t = frame * thisComp.frameDuration;
    if (above){
    if (P.valueAtTime(t) &lt; threshold){
    frame++;
    break;
    }
    }else if (P.valueAtTime(t) >= threshold){
    above = true;
    }
    if (frame == 0){
    break;
    }
    frame--
    }
    if (! above){
    t = 0;
    }else{
    t = frame * thisComp.frameDuration;
    }
    if(P == 0)value
    else
    {ease(time*200-t*200, 0, 100, [0,0], [0,1650-P])}

  • Xavier Gomez

    October 26, 2015 at 11:52 am

    We got pretty lucky there 😉

    For the other question i’m not optimistic.

    If you have several layers, the first expression can become slow.

    Now your second expression queries the value of that slider with a slow expression, and moreover asks that slow slider to look back in time at every frame. It can’t be fast.

    How many layers do you have ?
    Can you post a screenshot for both comps?
    Maybe there is another way to reach your goal.

    (Edit: in case you are wondering, your second expression does not look back until frame 0, it does stop when it finds a trigger so i don’t think it can be changed to something faster).

    Xavier.

  • Felix Weber

    October 26, 2015 at 2:27 pm

    Thanks again, but I just found a workaround.
    It won’t make sense to post it here, because it is very Porject-specific.
    But your first answer was the key to even finding a workaround 🙂

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