More Concise keyframe reference?

Community Beginner ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

Hi there! I'm relatively new to Java in AfterEffects. I know enough to do what I'd like, but I have a feeling there's an easier way to do it. If there any way to make this more concise, by not having to name every single keyframe specifically? Could I make a blanket statement to say, "If there is any keyframe, do this"?

L = thisLayer;
s = L.effect("Slide speed")(1)/29.97 // Slider determines how many frames slide will take

// Times of Keyframes
t1 = key(1).time;
t3 = key(2).time;
t5 = key(3).time;
t7 = key(4).time;
t9 = key(5).time;
t11 = key(6).time;

// Beginning points of slides, calculated from keyframes
t2 = t3-s;
t4 = t5-s;
t6 = t7-s;
t8 = t9-s;
t10 = t11-s;

// Values of Keyframes
v1 = valueAtTime(key(1).time);
v2 = valueAtTime(key(2).time);
v3 = valueAtTime(key(3).time);
v4 = valueAtTime(key(4).time);
v5 = valueAtTime(key(5).time);
v6 = valueAtTime(key(6).time);

// Sliding motions
slide1 = ease(time, t2, t3, v1, v2);
slide2 = ease(time, t4, t5, v2, v3);
slide3 = ease(time, t6, t7, v3, v4);
slide4 = ease(time, t8, t9, v4, v5);
slide5 = ease(time, t10, t11, v5, v6);

if (time<t2) {v1}
else if (time<t3) {slide1;}
else if (time<t4) {v2}
else if (time<t5) {slide2;}
else if (time<t6) {v3}
else if (time<t7) {slide3;}
else if (time<t8) {v4}
else if (time<t9) {slide4;}
else if (time<t10) {v5}
else if (time<t11) {slide5;}
else {v6}
TOPICS
Expressions , How to , Scripting

Views

83

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Feb 15, 2022 Feb 15, 2022
Try this:L = thisLayer; s = L.effect("Slide speed")(1)/29.97; val = value; if (numKeys > 0){ n = nearestKey(time).index; if (time > key(n).time) n++; if (n > 1 && n <= numKeys){ val = ease(time,key(n).time-s,key(n).time,key(n-1).value,key(n).value); } } val

Likes

Translate

Translate
Adobe Community Professional ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

Probably something like this:

L = thisLayer;
s = L.effect("Slide speed")(1)/29.97;
val = value;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (time < key(n).time) n--;
  if (n > 0 && n < numKeys){
    val = ease(time,key(n).time,key(n).time + s,key(n).value,key(n+1).value);
  }
}
val

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

Thanks! This worked perfectly. 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

Actually, I was mistaken. This code makes the motion start after it passes a keyframe, but I would like it to start leading up to a keyframe. Any idea how I would do that?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

Try this:

L = thisLayer;
s = L.effect("Slide speed")(1)/29.97;
val = value;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (time > key(n).time) n++;
  if (n > 1 && n <= numKeys){
    val = ease(time,key(n).time-s,key(n).time,key(n-1).value,key(n).value);
  }
}
val

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

LATEST

Perfect. Thanks again!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines