Notifications
Clear all

[Closed] Converting frames to time in hh:mm:ss

Hi, I’m hoping someone can point me in the right direction as I’m trying to get the
number of frames, and the time in hours minutes and seconds.

The number of frames I can work out mself, but I wonder if it is possible to get the
Time Configuration – Animation – Frame count and use it, instead of coding it. (not that important though)

The main one though is how do I best convert frames numbers into time, in hours mins and
seconds eg. 1 hr 22 mins 30 sec based on the frame number and then display it in a spinner.
Hopefully later, adjusting the spinner would also adjust the frame number.

@ 988f
00:00.39.52

So far I’ve got this:

a = 4800 – ticks per second
b = (currentTime as float)/a

but it’s giving me ie. 39.52 which is in seconds, at frame 988.
Is it a case of formatting? (not my strong suit) or is there a better way to do this type of thing?

9 Replies

here’s a script i put together to demonstrate how i would approach this
maybe there is room for optimization, but this way it’s easier to read i guess
of course you can ditch all that time callback stuff

just copy paste this into the maxscript editor and press evaluate
after you have done so, the current time values are printed in the listener each time the timeslider gets moved


-- make function-name global so we can remove and add the timecallback repeatedly
global timeFormat

(
    unregisterTimeCallback timeFormat

    -- some usefull constants
    ticksPerSec = (1s).ticks              -- 4800
    ticksPerMin  = ticksPerSec * 60    -- 288000
    ticksPerHour = ticksPerMin * 60    -- 17280000
    ticksPerDay = ticksPerHour * 24   -- 414720000 , unlikely but just in case

    function timeFormat=
    (
        -- now comes the fun part :  
        -- use modulo and division to "split" up ticks into time values

        -- how many days are in our time value ?
        days = (currenttime.ticks / ticksPerDay) as integer
        remainder = mod currenttime.ticks ticksPerDay

        -- take the remainder and calc hours from it
        hours = (remainder / ticksperHour) as integer
        remainder = mod currenttime.ticks ticksPerHour

        -- again take the remainder and calc minutes from it
        mins = (remainder / ticksPerMin) as integer
        remainder = mod currenttime.ticks ticksPerMin
		
        -- and again take the remainder and calc secs from it
        secs = (remainder / ticksPerSec) as integer

        -- now we only have left some rest, less than a second in ticks
        remainder = (mod currenttime.ticks ticksPerSec) as integer

        format "Current frametime:  % Days, %h : %m : %s . % ticks
" days hours mins secs remainder
    )
    registerTimeCallback timeFormat
)

Funny fact i found out during that :

Max’s timeline indeed accepts a huge frame range and is maxed out at
10.000.000 , which means 3 days 20h playing time if played back in realtime

I never wondered but there you go interesting
Thanks spacefrog that exactly what I needed.
I was going a little loopy trying to work this out


((dotnetclass "TimeSpan").FromTicks (TicksPerFrame * currenttime.frame)).ToString()

1 Reply
(@panayot)
Joined: 11 months ago

Posts: 0

hmm, sorry if i bother you… but that not work for me

for example:

at time 2002f should return “00:01:06:3520”
but it return “00:00:00.0320320”

at time 3000f should return “00:01:40:0000”
and not “00:00:00.0480000”

Ha ha , nice one Denis
Of course thats more efficient. I right jumped onto the topic without thinking of dotnet

honestly i didn’t test it. the main idea is pretty clear. as i really need it, i will fix it to be work.

2 Replies
(@panayot)
Joined: 11 months ago

Posts: 0

Yeah, the idea is very good, just was not sure if the code or my max fails. Here is what i done working using your idea with TimeSpan:

((dotnetclass "TimeSpan").FromSeconds (currentTime as float/TicksPerFrame/frameRate)).ToString()
(@denist)
Joined: 11 months ago

Posts: 0

there is some difference between max ticks and system ticks. i don’t know what the difference…
so the alternative .net solution is:


((dotnetclass "TimeSpan").FromSeconds (frames as float / frameRate)).ToString()