Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sliders to control time between keyframes

  • Dan Ebberts

    June 15, 2011 at 3:25 pm

    I guess it would be like this:


    holdTime = effect("Slider Control")("Slider");
    k1 = 2; // 1st hold keyframe
    k2 = 3; // 2nd hold keyframe
    k3 = 4;
    k4 = 5;
    k5 = 6;
    k6 = 7;
    k7 = 8;
    k8 = 9;
    k9 = 10;
    k10 = 11;
    p = transform.position;
    t1 = p.key(k1).time;
    t2 = t1 + holdTime;
    t3 = t2 + holdTime;
    t4 = t3 + holdTime;
    t5 = t4 + holdTime;
    t6 = t5 + holdTime;
    t7 = t6 + holdTime;
    t8 = t7 + holdTime;
    t9 = t8 + holdTime;
    t10 = t9 + holdTime;
    if (time < t1)
    t = time
    else if (time < t2)
    t = linear(time,t1,t2,t1,p.key(k2).time)
    else if (time < t3)
    t = linear(time,t2,t3,t2,p.key(k3).time)
    else if (time < t4)
    t = linear(time,t3,t4,t3,p.key(k4).time)
    else if (time < t5)
    t = linear(time,t4,t5,t4,p.key(k5).time)
    else if (time < t6)
    t = linear(time,t5,t6,t5,p.key(k6).time)
    else if (time < t7)
    t = linear(time,t6,t7,t6,p.key(k7).time)
    else if (time < t8)
    t = linear(time,t7,t8,t7,p.key(k8).time)
    else if (time < t9)
    t = linear(time,t8,t9,t8,p.key(k9).time)
    else if (time < t10)
    t = linear(time,t9,t10,t9,p.key(k10).time)
    else
    t = p.key(k10).time + (time - t10);
    valueAtTime(t)

    I haven’t tested this and there are probably better ways to code it, but hopefully it will do what you want.

    Dan

  • Lukasz Lindell

    June 17, 2011 at 10:38 am

    Thanks a lot Dan, that will work!

  • Greg Antisdel

    November 3, 2014 at 8:53 pm

    Hi Dan,

    This expression is awesome! I was wondering if we could specify a min and max range for the slider?

    For example, if the value entered by the slider is a negative number, the animation will continue normally up until the second keyframe and then the next frame it will snap to the fourth keyframe. If the value entered by the slider is longer than the animation, the third and fourth keyframes will never be reached.

    I was thinking something along the lines of

    if (holdTime<3);
    t=3
    else if (holdTIme>28);
    t=28
    else

    But I am obviously missing something.

    Any help would be greatly appreciated.

    Thanks

    Greg

  • Greg Antisdel

    November 4, 2014 at 3:34 pm

    I just figured out that I can set the range on the slider itself, so no need to worry about the code.

  • Hung Nguyendac

    December 25, 2014 at 10:13 am

    Hi Dan. Your code worked with “tranform”, but i wanna use this code for Shape “path\shape1\path-stroke-fill-tranform”.
    I was changed “p = transform.position; => p = contents.shape 1.path;”
    But it doesn’t work. Please help me.

  • Dan Ebberts

    December 25, 2014 at 6:37 pm

    Which property has the keyframes? Which property has the expression? Are you getting an error message? If so, what is it?

    Dan

  • Hung Nguyendac

    December 26, 2014 at 2:53 am

    I have 2 problems:
    1.I want to use your code with other properties. Ex. Shape and Mask (like this picture), but it always show error occurred at line 4. I think I was the wrong path.
    2. I had 12 keyframes.
    – If I start with “k1=2”, after I’m increased slider, then keyframes: 3,4,5,6,7,8,9,10,11,12 also increase value of the slider. I only want it to affect keyframes:11, k12
    – If I start with “k1=10” then the time of motion begins at keyframe 10 while I want it to start at keyframe 2. I don’t want it affect to keyframe 3->10

  • Dan Ebberts

    December 26, 2014 at 4:41 am

    Try changing the 4th line to this:

    p = thisProperty;

    and see if that eliminates the error. I’m not sure what the second part of your question is asking though.

    Dan

  • Hung Nguyendac

    December 28, 2014 at 10:52 am

    Thank Dan! I was corrected 2 problems.
    1. I used “p=thisProperty;” and it worked with Shape and Mask.
    2. I just change “t2 = t1 + holdTime;” => “t2 = t1 + holdTime – (second);”

    I have a new problem. I use this code. It can scale layer by slider, but it doesn’t work with keyframes in this layer. How to make it correct?

    x=100; //100% Comp
    y=100; //100% Comp
    t=thisComp.layer("Scale").effect("Scale Y")("Slider");
    if (t>=y)
    [x,y]
    else
    [x,t]

  • Dan Ebberts

    December 28, 2014 at 5:43 pm

    It’s hard to say for sure, but you might be looking for something like this:

    t=thisComp.layer(“Scale”).effect(“Scale Y”)(“Slider”);
    [value[0],value[1]*t/100]

    Dan

Page 2 of 3

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