Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can expression be calculated once?

  • Can expression be calculated once?

    Posted by Aleksandrs Valters on October 1, 2009 at 3:25 pm

    I have expression with loop. At the result of this expression i get some data (ex.[122,888]). AE every frame calculates this again and again… is it possible to tell expression to be calculated once (at frame number 1) and if i currently at frame number 3894 then just do nothing and leave data alone?
    Sorry again for my English.
    P.S. I try to make comp duration in 1 frame and create another comp where layer takes data from composition with calculation but without luck…

    Dan Ebberts replied 16 years, 7 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 1, 2009 at 4:13 pm

    No, an expression has to provide a value at each frame and it can’t pass information from one frame to the next. Even if you set up a 1-frame precomp and referenced its value using valueAtTime(0), the calculation would still be performed for each frame of your main comp.

    Dan

  • Aleksandrs Valters

    October 1, 2009 at 7:39 pm

    Thank you very mutch!

  • Dan Ebberts

    October 1, 2009 at 8:02 pm

    You could always convert the expression to keyframes. Not the greatest plan if you later need to change the expression, but in your one-frame precomp scenario it would keep from having to run the expression on each frame (I’m assuming it’s slowing your render down), and you’d only have one keyframe to clean up if you need to make changes.

    Dan

  • Aleksandrs Valters

    October 1, 2009 at 8:21 pm

    But is it possible to do kind of this thing with Script?
    Down i paste my expression thet i put in Point of control effect, that’s work fine. But it is not usable until this process (render) won’t be fast (ex. just one time calculation).
    p.s. if it is possible to do with script, i need to learn it fast from zero =)

    var xPosition = 0;
    var yPosition = 0;
    var compWidth=Math.round(thisComp.width/5);
    var compHeight=Math.round(thisComp.height/5);
    for (x = 1; x < compWidth; x++)
    {
    for (y = 1; y< compHeight; y++)
    {
    var samplePointXY=[x*5, y*5];
    var sampleRadius=[1,1];
    var sampledColor_8bpc=255*thisComp.layer("dot").sampleImage(samplePointXY, sampleRadius);
    var colorRed=Math.round(sampledColor_8bpc[0]);
    if (colorRed >190){
    var xPosition = x*5;
    var yPosition = y*5;
    break;
    }
    }
    if (xPosition>0)
    break;
    }
    [xPosition,yPosition]

  • Dan Ebberts

    October 1, 2009 at 8:27 pm

    Scripting doesn’t have anything like sampleImage(), so you’d have to have the script apply the expression to a layer, harvest the result, remove the expression and set a static value. Not trivial, but not too tough.

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