Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
malex
Topic Author
Posts: 20
Joined: Fri May 21, 2004 3:03 pm

Create a timecode with expressions

Thu Jun 03, 2004 11:10 am

Instead of using any timecode effect, you can very easily do this with expressions :

timeToCurrentFormat();


Apply this expression to a text layer's "source text" parameter.


Steps :
1/Create a text layer (type dummy text)
2/Twirl down to "Source Text"
3/Activate the expression field and paste the expression. It will basically give you the current timecode, so you can't really fake a different timecode (unless you move the layer around in time and precompose)
 
Guest

timecode

Wed Jun 09, 2004 10:36 am

The first argument to timeToCurrentFormat is the time you want to display in seconds. By default this is the current time -- you can display any timecode value this way without precomposing.

For example, timeToCurrentFormat(10)

gives you
0:00:10:00

or apply expr controls to the layer and use this:
timeToCurrentFormat(effect("Slider Control")("Slider")))

to get a slider with arbitrary timecode values
 
dfl10
Posts: 3
Joined: Tue Aug 30, 2005 3:51 am
Contact:

Tue Aug 30, 2005 5:56 am

Hi all,
i've tried the code above and with adding numbers to it to increase the starting TC... however when i add numbers over two digits log the timecode stops running and just shows that static number.:shock: as the timecode shows 00:00:00:00 (hours:mins:secs:frames) i'd love to be able to change the TC to start at for example 02:00:44:00 and then run from there. any ideas on how to make the expression do this without freezing the number?

any help really appreciated :)

/d
 
oscarus
Posts: 9
Joined: Mon Jul 12, 2004 4:35 pm
Location: Paris
Contact:

Tue Aug 30, 2005 7:42 am

Apply this expression
h=5;m=59;s=3;f=7;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%(1/thisComp.frameDuration);
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f
 
dfl10
Posts: 3
Joined: Tue Aug 30, 2005 3:51 am
Contact:

Tue Aug 30, 2005 8:31 am

brilliant!!! thanks oscarus! i just checked it out and it works beautifully! kinda get the code too, but what does the '%' do?

thanks.d :D
 
Colin Braley
Posts: 13
Joined: Thu Jul 14, 2005 7:33 pm
Location: VA
Contact:

Tue Aug 30, 2005 8:52 am

It's called the modulus (spelling?) operator. It's pretty much just means "the remainder of the division of the two numbers."
~Colin
 
dfl10
Posts: 3
Joined: Tue Aug 30, 2005 3:51 am
Contact:

Fri Sep 02, 2005 12:23 am

thanks guys! i've used the above script in different versions now and it workds great!! a quick other question about running numbers...

anybody have and idea how to script a number to run from a single 0 then automatically on to double digit and three digit as it needs?

/d :)
 
vidpat
Posts: 86
Joined: Thu Oct 21, 2004 12:36 am
Location: Phoenix, AZ
Contact:

Fri Sep 02, 2005 1:45 pm

The following expression will count an increasing monotonic sequence:
var nFrames = 30;
var startValue = 0;
timeToFrames() / nFrames + startValue;


The variables are for your convenience. startValue is the number from which to start counting. nFrames is the number of frames for which each value will be displayed. These, of course, may be tied to sliders if you wish.
 
sbucci
Posts: 1
Joined: Fri Jan 14, 2005 10:49 am

AE 7 adjustment to script?

Tue Apr 11, 2006 11:58 am

I'm trying the script in AE 7 and entered Ocscarus script, which worked great, except I get the frames going into decimal places. I tried the last script in the thread, thinking that eliminated the problem, but maybe I did it wrong.

Do those two scripts go together? If so, does one go before the other?

I want to keep frames from going into decimal places.

Thanks.
Steve Bucci
Media Specialist
 
philspitler
Posts: 39
Joined: Wed Nov 02, 2005 10:20 am
Contact:

Try This

Sun Apr 16, 2006 11:55 am

I just added a Math.round function to the frames and it seems to have fixed the issue.

Phil



h=0;m=0;s=0;f=0;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=Math.round(f%(1/thisComp.frameDuration));
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f
Phil Spitler
 
philspitler
Posts: 39
Joined: Wed Nov 02, 2005 10:20 am
Contact:

Ooops

Sun Apr 16, 2006 12:01 pm

The version I just posted seems to have a rounding error.

When I get to 00:00:24:30 ..... it all slips by a frame.

sorry.

Phil
Phil Spitler
 
fletty
Posts: 1
Joined: Tue May 02, 2006 3:44 pm

Wed May 03, 2006 1:16 am

i needed to create a 72 hour countdown with milliseconds instead of frames.

and so i tried for ages (i've never used expressions before today) to get it to work using the code above. finally got it working

h=71;m=59;s=59;f=99;
f-=timeToFrames(t = time + thisComp.displayStartTime, fps = 3.99 / thisComp.frameDuration, isDuration = false);
s+=Math.floor(f/99);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%99;
s=s%60;
m=m%60;
if(f<0) {f=100+f}
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f

I changed it to f-= and some other stuff too.

can someone please inform me if this is the best way to do this? and/or ways i can improve the code for this task.

cheers :D
 
drswoboda
Posts: 3
Joined: Tue May 16, 2006 10:35 pm

Wed May 31, 2006 5:28 pm

I noticed that this cool expression doesn't work with NTSC D1 29.97 video. Anyone out there smart enough to get this to work with Drop Frame and Non-Drop Frame video?

Here is a reference on the math. . .
http://teched.vt.edu/gcc/Html/VirtualTe ... mecode.pdf

This would be very useful.
Thanks,

-David
 
Jumpcuts
Posts: 1
Joined: Mon Jan 08, 2007 1:53 pm
Location: Boston
Contact:

Try this small alteration

Mon Jan 08, 2007 8:35 pm

f=Math.round(f%(1.001/thisComp.frameDuration));


If you look at the PDF file you will see why this works. time code is not 60 fields per second but 59.97 fields per second, or 001% slower than 60 fields per second. (In my comp I changed all the 60's to 59.97 as well, but it did not seem to matter for the round up)

Anyway this worked for me, then I put the comp in a new comp and used the "Time reverse Layer" command (Under the Layer menu tree) to make it a cound down instead of a count up.

hope this helps.

SMA


drswoboda wrote:
I noticed that this cool expression doesn't work with NTSC D1 29.97 video. Anyone out there smart enough to get this to work with Drop Frame and Non-Drop Frame video?

Here is a reference on the math. . .
http://teched.vt.edu/gcc/Html/VirtualTe ... mecode.pdf

This would be very useful.
Thanks,

-David
 
pickle
Posts: 1
Joined: Wed Apr 22, 2009 3:48 am

Re: Create a timecode with expressions

Mon Apr 27, 2009 4:35 am

oscarus wrote:
Apply this expression

h=5;m=59;s=3;f=7;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%(1/thisComp.frameDuration);
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f



Thanks Oscarus! This has just really helped me out. :)

Who is online

Users browsing this forum: No registered users and 2 guests