ScriptSpot home

Forum topic · General Scripting

currentTime on spinner

By Clément Plantec · 2013-12-07

Description

Hi guys

I have an issue to get the currentTime in real time while playing an animation in a spinner.

I can easily get the CurrentTime in a spinner like this:


spn_CT.value = currentTime

but this way it's not in real time while playing an animation.

If anyone have an idea, thanks a lot :)

Comments (18)
Clément Plantec

What I want is to get every frame number you go trought in the spinner while playing an animation.
for exemple, if you have an animation range of 25 frames that begin at frame 0, I want my spinner to show 0,1,2,3,4,5,6....23,24,25 while playing the animation, like the timeslider.

.

This will prints the curent frame number as it is shown in the time slider:


spn_Time.value = (slidertime as string)as integer

Or you can use this:


spn_Time.value = (slidertime.frame as integer)
Reply to miauu
Clément Plantec

Thanks for your help.
Unfortunately, this is not what I want, and barigazi give me a great solution ^^

Reply to Clément Plantec
Branko Živković

I love to connect spinner and timeslider like this

try(destroyDialog ::testRoll)catch()
rollout testRoll "• • •"
(
spinner spn_CT "" pos:[5,5] fieldwidth:80 type:#integer
timer timeTick interval:30
on spn_CT changed val do
(
if (case1 = val < animationRange.start.frame) or (case2 = val > animationRange.end.frame) then
(
val = if case1 then animationRange.start.frame else animationRange.end.frame
)
else slidertime = val
)
on timeTick tick do
(
if spn_CT.value != sliderTime do spn_CT.value = sliderTime
)
on testRoll open do timeTick.active = on
on testRoll close do timeTick.active = off
)
createDialog testRoll 100 25 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Reply to Branko Živković
Clément Plantec

Thanks I'm gonna check this.

I didn't know the timer UI, but if I try to understand what you did, you have connected the value of the spinner to the timer, so the spinner change its value every 30 miliseconds according to the sliderTime ?

Reply to Branko Živković
Clément Plantec

I really need to thank you again, the timer is really useful. You just changed the whole way i'll script with mxs ^^

Reply to Clément Plantec
Branko Živković

My pleasure.
BTW using callbacks are good way to monitor something but only if you know to work with them. But timer is very easy to use and control, also when you play with .net stuffs then .net timer will save your life :)
Cheers!

Reply to Branko Živković
Clément Plantec

Ok good to know :)
But for now I really don't like to use callback and .net since I don't understand them ^^ (and I read that .net has been badly integrated in max...)

Otherwise, any idea how to open the time configuration dialog via MXS ?

Reply to Clément Plantec
Branko Živković

Who told you that .net is bad implemented in max?
Maybe python but .net is long time here and you can do awesome "magic" stuffs with it.

--open the time configuration dialog
max time config

Reply to Branko Živković
Clément Plantec

No one in particular, just read it sometimes.
But I know you can do some very nice stuff with, I already give it a try, but it really hurt my brain :p
Since I don't have any good knowledge on programing, for know I prefered to focus on mxs.
I will also begin to learn C, but mostly I'm a 3D artist so I prefer to do 3D stuff than scripting ^^

thanks for the help anyway :)

Clément Plantec

Hi barigazi, always here to help me :)

Thanks but it's not working (actually it's the way I defined the spinner).

Maybe you didn't understand what I mean, so i'll try to explain a bit better.

for example, if you use this:


fn time_p = print currentTime
registerTimeCallback time_p

you'll see in the listener that you print every frame while playing the animation, and this is what I want in my spinner.


unregisterTimeCallback time_p

=> to delete the callback if you try it :)

Reply to Clément Plantec
Branko Živković

Are you vant to unregisterTimeCallback if you spinner value is greater then or lower then animation range?

Reply to Branko Živković
Branko Živković

If Yes then

on spn_CT changed val do
(
if val < animationRange.start.frame or val > animationRange.end.frame then
(
unregisterTimeCallback time_p
)
else slidertime = val

)

Branko Živković


spn_CT.value = slidertime