Notifications
Clear all

[Closed] timeStamp() and the timeSlider

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
" ((end - start) / 1000.0)
		
	)
)
createDialog TestTimer

Best regards,
John

2 Replies

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
" ((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
 

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
" ((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