ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Create interval tweens by pairs of markers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shin Huynh
Create interval tweens by pairs of markers
on Sep 20, 2019 at 10:51:12 am

I would like to create a box moving forward 100 px in among of multi pairs of markers called IN and OUT ,
so on the timeline , every time the time hits IN markers, the box start moving and stop at OUT markers (like a car moves straight on the street and meets red lights) , i have read a thread about changing opacity but the scripts is for ping pong animation and not suit for this situation . Hope for some help


Return to posts index

Dan Ebberts
Re: Create interval tweens by pairs of markers
on Sep 20, 2019 at 7:07:18 pm

This is pretty basic. It should move 100px to the right for each pair of "IN" and "OUT" markers.


pixPerMove = 100;
accum = 0;
m = marker;
doingIn = false;
if (m.numKeys > 0){
inKey = 0;
idx = 1;
while (idx <= m.numKeys && m.key(idx).time < time){
if (m.key(idx).comment == "IN"){
doingIn = true;
inKey = idx;
}else if (m.key(idx).comment == "OUT"){
doingIn = false;
accum++;
}
idx++;
}
}
if (doingIn){
for (i = idx; i <= m.numKeys; i++){
if (m.key(i).comment == "OUT"){
tIn = m.key(inKey).time;
accum += (time - tIn)/(m.key(i).time - tIn);
break;
}
}
}
x = accum*pixPerMove;
value + [x,0]



Dan



Return to posts index

Shin Huynh
Re: Create interval tweens by pairs of markers
on Sep 21, 2019 at 3:32:30 am
Last Edited By Shin Huynh on Sep 21, 2019 at 4:14:41 am

You such a talent , Dan , i was waiting for your reply
it works perfectly
could you explain your method ?

actually i created my own from Expression for IN and OUT opacities i mentioned and it worked , but it used nearestkey and linear so i had to break the tween into 2 parts ,from "IN to the middle" and "the middle to OUT" then among the tweens i need to stop the value ,
i'm an animator not a developer , but i like to use scripts for my tasks , here is my script , it's so confused but luckily it worked , you can check and correct it

m = 0; // marker index
fadeFrames = 0;
Finalvalue = value[0];
Incount = -100;
t = time;
if (marker.numKeys > 0)
{
m = marker.nearestKey(time).index;
tag = marker.key (m).comment;
n=m;
while (n>0)
{
tagn = marker.key (n).comment;

if (tagn == "In" && time>=marker.key(m).time)
{
Incount = Incount+100 ;
}
else if (tagn == "Out" && time<marker.key(m).time)
{
Incount = Incount +100;
}
n--;
}
if (tag == "In"){t = time - marker.key (m) .time;}
else if (tag == "Out"){ t = time - marker.key (m-1) .time;}

if (2<m<marker.numKeys && tag == "In"){
fadeFrames = marker.key(m+1).time - marker.key(m).time;}
else if (2<m<marker.numKeys && tag == "Out" && time <marker.key(m).time ){
fadeFrames = marker.key(m).time - marker.key(m-1).time;}

else { fadeFrames = 0;}

}

else { Incount = 0;}



if ((tag == "In" && time>=marker.key(m).time) ||(tag == "Out" && time<marker.key(m).time)) { Finalvalue =linear (t, 0, fadeFrames , Finalvalue+Incount, Finalvalue+Incount +100) }

else { Finalvalue =linear (t, 0, fadeFrames , Finalvalue+Incount+100, Finalvalue+Incount+200) }

value =[Finalvalue,0];


Return to posts index


Dan Ebberts
Re: Create interval tweens by pairs of markers
on Sep 21, 2019 at 6:00:18 am

>could you explain your method ?

The first part of the expression counts how many IN/OUT marker pairs have occurred before the current time (stored in variable accum). The second part checks to see if the current time is inside an IN/OUT marker pair, and if so, calculates the fraction of the marker pair duration that has elapsed and adds that value to variable accum. Finally the total movement is calculate by multiplying accum by 100 pixels.

Dan



Return to posts index

Shin Huynh
Re: Create interval tweens by pairs of markers
on Sep 22, 2019 at 5:20:34 am

yeah , now i understood all your script lines , but it's difficult to figure out the idea to make the script , loop in expression is hard to understand , you made an increasement loop , and i used a count down one , you got a smooth solution ๐Ÿ‘๐Ÿ‘๐Ÿ‘


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]