PDA

View Full Version : timeStamp() and the timeSlider


JohnnyRandom
01-23-2009, 05:06 PM
I was hoping maybe someone knows a better way to do this (maybe a little more accurate) The script takes the animation range or defined range and timestamps the duration it takes to run through the specified duration. As you can see it moves the timeslider in a loop, this works for comparison purposes of different setups but is not a very accurate evaluation of the true time it takes. I tried for a little bit trying to use the playAnimation() and isAnimplaying() functions with zero success, since max seems to lock just about everything out when the playAnimation() function is invoked.

Any ideas? (lol, other than user a stopwatch :D)


try(destroydialog TestTimer)Catch()
rollout TestTimer "Timeline Timer"
(
local start
local end
local numframes
local s = animationRange.start as integer
local f = animationRange.end as integer
local startFrame = s / ticksperframe
local endFrame = f / ticksperframe
button btn_start "Start"
spinner spn_startFrame "Start Frame" range:[0,10000000,startFrame] type:#integer scale:framerate
spinner spn_endFrame "End Frame" range:[0,10000000,endFrame] type:#integer scale:framerate

on btn_start pressed do
(
slidertime = spn_startFrame.value
numFrames = spn_endFrame.value - spn_startFrame.value
start = timeStamp()
for i = 1 to numFrames do
(
slidertime += 1
)
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)

)
)
createDialog TestTimer

Best regards,
John

ZeBoxx2
01-23-2009, 05:40 PM
perhaps something along these lines, using a time change callback?


global timeCheck -- better make sure the callback function can find itself

fn timeCheck = (
if (sliderTime == animationRange.end) do ( -- at the end yet?
endTime = timeStamp() -- stop the stopwatch
format "Time taken: %s\n" ((endTime - startTime) / 1000.0) -- display the time
unRegisterTimeCallback timeCheck -- kill the callback
)
)

playbackloop = false -- no looping to make sure we end up on the last frame
realtimePlayback = false -- even if realtime playback is true
playActiveOnly = true -- only play back the active range
sliderTime = animationRange.start -- go to the beginning
registerTimeCallback timeCheck -- set up our callback
startTime = timeStamp() -- start the stopwatch
playanimation() -- start playing back

JohnnyRandom
01-23-2009, 05:50 PM
Excellent, works a charm.:)

Thanks, must learn about callbacks.

try(destroydialog TestTimer)Catch()
rollout TestTimer "Timeline Timer"
(
global timeCheck -- better make sure the function can find itself
local s = animationRange.start as integer
local f = animationRange.end as integer
local startFrame = s / ticksperframe
local endFrame = f / ticksperframe

spinner spn_startFrame "Start Frame" range:[0,endFrame,startFrame] type:#integer
spinner spn_endFrame "End Frame" range:[startFrame,100000,endFrame] type:#integer
button btn_start "Start" pos:[14, 42] height:18 across:3
label lbl_totalTime "0.000" pos:[74, 44]
label lbl_seconds "seconds" pos:[114, 44]
on spn_endFrame changed endVal do
(
endFrame = endVal
)
on spn_startFrame changed startVal do
(
startFrame = startVal
)

fn timeCheck =
(
if (currentTime == endFrame) do ( -- at the end yet?
stopAnimation()
endTime = timeStamp() -- stop the stopwatch
lbl_totalTime.text = ((endTime - startTime) / 1000.0) as string
format "Time taken: %s\n" ((endTime - startTime) / 1000.0) -- display the time
unRegisterTimeCallback timeCheck -- kill the callback
)
)
on btn_start pressed do
(
playbackloop = false -- no looping to make sure we end up on the last frame
realtimePlayback = false -- even if realtime playback is true
playActiveOnly = true -- only play back the active range
sliderTime = spn_startFrame.value -- go to the beginning
registerTimeCallback timeCheck -- set up our callback
startTime = timeStamp() -- start the stopwatch
playanimation() -- start playing back
)
)
createDialog TestTimer

CGTalk Moderation
01-23-2009, 05:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.