Activity › Forums › Adobe After Effects Expressions › Index/Time of a marker according to comment
-
Index/Time of a marker according to comment
Dan Ebberts replied 11 years, 11 months ago 2 Members · 14 Replies
-
Benoit Kergosien
July 5, 2014 at 1:47 pmWhat I’m doing wrong here ?
The increment doesn’t work properly, it only stores the first marker in my array.
Thanks.
Benoit
var arrayMarker=[];
m=marker;
if (m.numKeys>1){
for (i=1; i<=m.numKeys; i++){
arrayMarker.push(m.key(i).comment);
arrayMarker[0];// test if expression works, it only managed with the first marker ie [0]
}
}
else
{
value;
}
-
Dan Ebberts
July 5, 2014 at 5:08 pmI think you just need to move the statement that accesses the array so that it’s outside the loop that builds the array:
var arrayMarker=[];
m=marker;
if (m.numKeys>1){
for (i=1; i <= m.numKeys; i++){
arrayMarker.push(m.key(i).comment);
}
arrayMarker[2];
}else{
value;
}
Dan
-
Benoit Kergosien
July 6, 2014 at 3:55 pmHi Dan,
I did your corrections, thanks It works like it should.
I had this piece of code to the previous expression and I’m close to make it work.
The only problem is that the value returned since the last marker’s time is the marker’s index, how to avoid this?
Thanks again Dan, with all your help my abilities in expressions has already improved.
Benoit
m = marker;
prev = 0;
next = 0;
var arrayMarker=[];
var valueMarker=[];
markerComment="";
if (m.numKeys > 1){
nearest = m.nearestKey(time);
for (i=1; i<=m.numKeys; i++){
arrayMarker.push(m.key(i).comment);
}
for (i = 0; i < arrayMarker.length; i++) {
if (arrayMarker[i] == '') {
valueMarker.push(0);
}
else if (arrayMarker[i] == 'RIO') {
valueMarker.push(20);
}
else if (arrayMarker[i] == 'TOKYO') {
valueMarker.push(50);
}
}
if (nearest.time <= time){
prev = nearest.index;
if (prev < m.numKeys){
next = prev+1;
}
}else{
next = nearest.index;
}
if (next > 1){
prev = next-1;
}
if (prev != 0 && next != 0){
t1= m.key(prev).index;
t2=m.key(next).index;
markerComment=m.key(t1).comment;
if (markerComment==arrayMarker[t1-1]) {
Math.floor(linear(time,m.key(t1).time,m.key(t2).time,valueMarker[t1-1],valueMarker[t2-1]));
}else{
null // only have 1 marker -- add some code to deal with that
}
}
}else{ // no markers
0;
} -
Dan Ebberts
July 6, 2014 at 9:49 pmIt’s still not completely clear to me how you want this to work, but this is my guess:
m = marker;
prev = next = 0;
var arrayMarker=[];
var valueMarker=[];
if (m.numKeys > 1){
nearest = m.nearestKey(time);
for (i = 1; i <= m.numKeys; i++){
markerComment = m.key(i).comment;
arrayMarker.push(markerComment);
if (markerComment == 'RIO'){
valueMarker.push(20);
}else if (markerComment == 'TOKYO') {
valueMarker.push(50);
}else{
valueMarker.push(0);
}
}
if (nearest.time <= time){
prev = nearest.index;
if (prev < m.numKeys){
next = prev+1;
}
}else{
next = nearest.index;
}
if (next > 1){
prev = next-1;
}
if (prev != 0 && next != 0){
Math.floor(linear(time,m.key(prev).time,m.key(next).time,valueMarker[prev-1],valueMarker[next-1]));
}else{
0;
}
}else{ // no markers
0;
}
Dan
Reply to this Discussion! Login or Sign Up