ScriptSpot

Forum topic · General Scripting

currentTime on spinner

By SugaR · 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)

SugaR · 2013-12-07

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.

.

miauu · 2013-12-07

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)

SugaR · 2013-12-07

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

barigazy · 2013-12-07

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)

SugaR · 2013-12-07

Thanks a lot barigazy, exactly what I need :)

barigazy · 2013-12-07

If you need advanced solution see this tool and check out "Tune" tab.
You can find playback controls

SugaR · 2013-12-07

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 ?

barigazy · 2013-12-07

Yup :)

SugaR · 2013-12-07

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

barigazy · 2013-12-07

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!

SugaR · 2013-12-07

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 ?

barigazy · 2013-12-07

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

SugaR · 2013-12-07

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 :)

SugaR · 2013-12-07

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 :)

barigazy · 2013-12-07

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

barigazy · 2013-12-07

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

)

barigazy · 2013-12-07


spn_CT.value = slidertime

barigazy · 2013-12-07

If you vant to get slider time in seconds then try like this

slidertime.frame/framerate