 Adobe After Effects Expressions ForumTimecode Expression
Timecode Expression
by Scott McGee on Feb 26, 2019 at 12:48:33 pm

Just because someone has asked a question and it's made me think.

How can you use an expression on time use the timecode to trigger.

eg

If (time < 2) 100 else 0;

if I do frames this also works

if (time < framesToTime(65)) 100 else 0;

But how can you use the timecode to do the same

if (time < timeToTimecode(00:00:02:00)) 100 else 0;

This doesn't work and I can't fathom how to do it another way. Surely if it works for time and frames. It can do timecode.

Re: Timecode Expression
by Alex Printz on Feb 26, 2019 at 4:14:51 pm

isn't timecode technically a string? You would need a function timecodeToTime(t), which after effects doesn't have, to get it to be comparable.

To build the function you you would need to parse out the separate elements of the timecode and combine them appropriately, e.g.:

t = 00:00:02:00;

var f = 0;
for(i=0; i<4; i++){
d = t.split(":")[i];
try{d = d.split(":")}catch(e){};
f += parseInt(d);
if(i<2) f*=60;
if(i==2)f*=(1/thisComp.frameDuration);
} framesToTime(f)

Alex Printz
Mograph Designer

Re: Timecode Expression
by Scott McGee on Feb 27, 2019 at 8:41:26 am

Cheers Alex,

I would never have thought of doing that.

I did get an error back because the timecode wasn't in "", but then it worked perfectly

t = "00:00:02:00";

var f = 0;
for(i=0; i<4; i++){
d = t.split(":")[i];
try{d = d.split(":")}catch(e){};
f += parseInt(d);
if(i<2) f*=60;
if(i==2)f*=(1/thisComp.frameDuration);
}

if(time < framesToTime(f)){
100
}else{
0
};