[Closed] how to stop animation
As silly as it sound I’cant figure this out. I mast check current fps . I could do it by
viewport.GetFPS() by I have to be sure I’m counting fps for right viewport with all object visible so I set perspective view and tried to do this:
playanimation()
viewport.GetFPS()
stopanimation()
But animation don’t stop, In help there is said playanimation() can’t be stoped by stopanimation() only if stopanimation() will be call by user in code inste button so I put stopanimation() to different button and used accesor to press this button but it also wan’t work So how to start and stop animation to get fps from viewport. It can be also playing some animation range let say play from frame 0 to 10 but what if current range will be set from 100 to 200. Is there any way to do this?
This works. What the help says is that you cannot stopAnimation() after playAnimation() inside the same function because playAnimation() is thread-blocking.
This won’t work:
(
fn playAndStopAnimation =
(
playAnimation() -- will freeze here until you stop the animation yourself in 3dsmax UI
stopAnimation()
)
playAndStopAnimation()
)
But calling stopAnimation() in a ui handler is totally possible:
rollout roll "roll"
(
button btn_start "Start"
button btn_stop "Stop"
on btn_start pressed do playAnimation()
on btn_stop pressed do stopAnimation()
)
createDialog roll
It can be also playing some animation range let say play from frame 0 to 10 but what if current range will be set from 100 to 200. Is there any way to do this?
Here it is:
(
animationRange = interval 100f 200f -- set a sample animation range
rollout roll "roll"
(
button btn_start "Start"
button btn_stop "Stop"
local previousAnimRange -- variable to store the animation range once you press "Start"
on btn_start pressed do
(
previousAnimRange = animationRange -- store the current animation range
animationRange = interval 10f 20f -- change the animation range to what you want
playAnimation()
)
on btn_stop pressed do
(
stopAnimation()
animationRange = previousAnimRange -- restore the previous animation range stored in previousAnimRange
)
)
createDialog roll
)
Thanks feranti you save me again but I know that. It,s not the point. I don’t want user to press any button to stop animation. I want to do it via maxscript, just:
Maxscript do: 1 – play animation, 2 – get fps, 3 – stop playing animation, that’s it.
I can’t involve user in my internal script action. It seem that everything is possible from maxscript but this one is so obvious it should be piece of cake but it’s not. Is there any way to do it automaticly. I can believe the most important option in max is so problematic. By the way, thank you for your previous help with calculating object distance it was very usefull. Ok its 1o clock, full moon. I have no idea how to solwe it, I search everywhere, would be great if somebody could help.
There are many problematic things in maxscript but this is not one of them. If you have a rollout, use maxscript timer, if not, use .NET timer:
(
local stopWatch = dotNetObject "System.Windows.Forms.Timer"
stopWatch.Interval = 250
local counter = 0
fn onTick sender args =
(
if counter == 0 then playAnimation()
else
(
stopAnimation()
sender.Stop()
dotNet.removeAllEventHandlers sender
sender.Dispose()
)
counter += 1
)
dotNet.AddEventHandler stopWatch #tick onTick
stopWatch.Start()
)
Thankyou very much, I’ll check it. In meantime I work around this problem like this:
—— GET FRAMERATE
—- get animation settings
playActiveOnly
timeConfiguration.realTimePlayback
animationloopmd=timeConfiguration.playbackLoop
animationrangemd=animationRange
timeConfiguration.playbackLoop =false
animationRange = interval 0 30
— play animation
playAnimation()
–get fps
currentfpsmd=viewport.GetFPS()
— stop animation and recover user animation settings
timeConfiguration.playbackLoop=animationloopmd
animationRange=animationrangemd
stopanimation()
you can’t get the right frame rate the way your doing above. see the help file for better understanding how viewport.GetFPS() works.
So is there any hope to get current fps from viewport? It getting more problematic then I assumed.
in help:
“Returns the last frame rate value in frames per second calculated by the Show Statistics overlay for the current viewport. If the viewport’s Show Statistics option is not turned on, the value will not represent the current frame rate of the viewport.
Available in 3ds Max 9 and higher.
In 3ds Max 2008 and higher, if the Adaptive Degradation is turned on, the value reported will be the target frame rate, not the actual frame rate.”
But even when I set statistic on and Adaptive Degradation off still fps shown by viewport.GetFPS() is way different than statistc show in spite of statistc indicate 2fps for each frame even last frame shown by vewport.GetFPS() should also idicate 2fps but it indicate 7 or more.
you thought wrong. sometimes a computation of a particle system behaviour takes 90% of its render time (especially in viewport)