Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Looping an expression with no keyframes

  • Looping an expression with no keyframes

    Posted by Ken Ackerman on August 5, 2013 at 6:08 pm

    Hello folks,

    I am trying to loop a property that has no keyframes and is only driven by a time expression, but I keep getting an error that the loop expression is looking for keyframes.

    Here is what I have so far:

    I am using the Beam effect, it’s Time property, I want it to cycle between 0>100 over the period of 1 second (but I want to be able to adjust that with an expression slider, hence why I am not simply placing keyframes):

    time * (100); //This makes a line shoot across the screen over the period of 1 second

    I want that to cycle. But when I try to add loop, after effects asks for keyframes, here is what I’m trying:

    time * 100;

    Anyone know of a way to make this work?

    Thanks in advance for the help!


    Alex Ezorsky replied 1 year, 1 month ago 3 Members · 9 Replies
  • 9 Replies
  • Ken Ackerman

    August 5, 2013 at 6:20 pm

    I found a way to resolve this using another post that Dan Ebberts answered. Though I’m not sure if there is an easier way to do it.
    This is the post that I got it from:

    This is my final expression and it seems to do the trick quite nicely:

    holdTime = effect(“line_passage”)(“Slider”);
    k1 = 1; // 1st hold keyframe
    k2 = 2; // 2nd hold keyframe
    p = effect(“Beam”)(“Time”);
    t1 = p.key(k1).time;
    t2 = t1 + holdTime;
    if (time < t1)
    t = time
    else if (time < t2)
    t = linear(time,t1,t2,t1,p.key(k2).time)
    t = p.key(k2).time + (time – t2);

    loopOutDuration(type = “cycle”, duration = 0)

  • Ken Ackerman

    August 5, 2013 at 6:26 pm

    Actually, I spoke too soon, that expression works, until I add the loop to it. Then it seems to override the time remapping expression and just loops the default duration of the keys as though the preceding code didn’t exist.
    Back to the drawing board.

  • Ken Ackerman

    August 5, 2013 at 6:37 pm

    Okay, I found a solution to my problem, again thanks to a post from Dan Ebberts.

    Thanks Dan,


  • Dan Ebberts

    August 5, 2013 at 6:39 pm

    I was going to suggest this:

    period = 1;
    t = time%period;


  • Ken Ackerman

    August 5, 2013 at 7:06 pm

    Thanks Dan,

    I think I understand how this is working, using time to create the loop. Pretty basic stuff, but seems quite useful.

    I appreciate the help,


  • Alex Ezorsky

    March 27, 2023 at 3:39 pm

    I too was looking to loop a period of time via expressions only. This:

    period = 1;

    t = time%period;

    is the closest I’ve gotten so far but to be honest I don’t fully understand how it works enough to modify for my purpose. I would really appreciate any help deconstructing this. The link you posted above to Dan’s “solution” no longer works :/


  • Dan Ebberts

    March 27, 2023 at 3:43 pm

    What do you want it to do?

  • Alex Ezorsky

    March 27, 2023 at 4:35 pm

    Dan you are an absolute genius. In the last hour some deep subconscious part of my brain was able to understand your previous expression enough to edit it to make it work for my purposes. I would still love an untangling of the time%period part but in the meantime I’ll explain my situation and resulting solution:

    I am making a short film where my hair and clothes change every frame of the video. In some scenes there are as few as 8 takes to cycle through and in others closer to 14. To achieve this I’ve put an expression on every layer that says to only be visible when it’s index matches the number on a slider called “layer selector”. Previously I had been animating that “layer selector with keyframes but it became increasingly frustrating when I wanted to adapt to different numbers of layers and still have the layers show equally long. This became even more frustrating when I wanted to experiment with the video frame rate. In any case the following was bashed together with trial and error and as I said probably some unconscious understanding. It works fabulously. Not only do I only have to enter the start and end layer to cycle through but now it shows each layer for exactly the right number of frames given the frame rate I’m choosing through the posterize time effect. In this case it cycles through layers 2-8 changing every 3 frames because my comp is 30fps and my posterize time is at 10fps.

    var startlayer = 2;

    var endlayer = 8;

    var compframerate = 1/thisComp.frameDuration;

    var numberoflayers = endlayer-startlayer;

    var period = (numberoflayers+1)*(compframerate/effect(“Posterize Time”)(“Frame Rate”));

    var t = timeToFrames(time)%period;


  • Alex Ezorsky

    March 27, 2023 at 4:47 pm

    Ok probably the last post but thanks to Dan’s reply in the adobe forum the new cleanest version is this:

    startlayer = 2;

    endlayer = 8;

    compframerate = 1/thisComp.frameDuration;

    framerate = (compframerate/effect(“Posterize Time”)(“Frame Rate”);

    numLayers = endlayer – startlayer + 1;

    currentLayer = Math.floor(timeToFrames(time)/framerate)%numLayers + startlayer;

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