Notifications
Clear all

[Closed] Run script every frame?

Hi I’m wondering if its possible to do so a command runs every frame when the time-bar/track-bar is playing?

Theoretical code:

on playanimation() pressed do
(
if (slidertime == currenttime) == true then
(
print “this massage every frame”
)
)

EDIT: —————
think this is closer to reality (still don’t working)

if isAnimPlaying() == true then
(
for i = animationRange.start to animationRange.end do
(
sliderTime = i
print”this every frame”
)

)

thanks in advance

17 Replies

registerTimeCallback ?

4 Replies
(@patan77)
Joined: 10 months ago

Posts: 0

thank you i think that will work, but now when i have registerTimeCallback
example:
fn time_p = print currentTime
registerTimeCallback time_p

then i cant unregisterTimeCallback??

(@panayot)
Joined: 10 months ago

Posts: 0

well, the same story here. usually unRegisterTimeCallback() works, but not alway. using reference function, as shown in the help, and redefine it to empty function, is the only workarrownd i know.

(@denist)
Joined: 11 months ago

Posts: 0

it always works. if it doesn’t work, you do something wrong.

(@panayot)
Joined: 10 months ago

Posts: 0

hmm, i read this conclusion from you for a 2nd time. maybe a new topic with example code (from you) which to be tested from many peoples can proof/clarify this subject just an idea

I have solved my problem now without using RegisterTimeCallback(), the problem where that when i animated the strength of an opacity map then it didn’t update in the view-port when i pressed play, but if i didn’t have an opacitymap and only animated the opacity instead then it would update so i skipped the opacity map.
Thanks anyway RegisterTimeCallback() is a good command to know

no… the issue needs a sample where unRegister is not working.

2 Replies
(@panayot)
Joined: 10 months ago

Posts: 0

This is your point of view. My idea was to ask for the user voice about this, instead of just to repeat that I do something wrong, and show me/us how looks like wrong procedure and how looks like correct procedure. Also in case enough peoples participate in such exercise there is some possibility and you to learn something. Its come to you, this is just idea, but keep in mind that w/o clarifying this I’ll ignore your opinion about unRegister.
And peace after all!

(@patan77)
Joined: 10 months ago

Posts: 0

Hi I’m probably doing wrong but I can’t use unRegistercallback, i wanted to use this now for a new thing that i’m working on, anyhow this is what i do when testing it in the MAXScript Listener:
I fist run the lines in box 1(img) then it registers so when i move the trackbar the command work then when i run the line in box(2) to unregistered then it say OK but then when i move the trackbar it still is registered. what am I doing wrong?
thanks in advance

 lo1

what is printing “No” ??

1 Reply
(@patan77)
Joined: 10 months ago

Posts: 0

its that i run registercallback test_01 = print”no” to see if that replaced the test_01 = print”yes” but the only thing that happened where that both showed up instead -.-

 lo1

It works fine for me. Which version of 3dsmax are you using?

1 Reply
(@patan77)
Joined: 10 months ago

Posts: 0

i’m using 2012 64bit and have all service packs and hot fixes :surprised

 lo1

Works for me on that version :shrug:
Try to restart max, register just one function (without overwriting it) and then unregister it.

1 Reply
(@patan77)
Joined: 10 months ago

Posts: 0

Wow hmm Now when i restated max it worked I tried it yesterday didn’t work then i turned off the computer and when i tried it today still didn’t work and i have restated max several times today and tried but still didn’t work then now when u say that i should restart and try and now it worked so thank you :applause: i’m glad to know that I had the right code

with so many restarts for one positive result, am sure you’ll come in troubles again, as the folk story say “where is leak will flow”.
looks like stability of unreg-function is too speculate subjects, so im off on this subject.

i think you do something wrong. read this part from the MXS Help more careful:

[left]Note that it is the function value that is being registered, not the function name or global variable. This means that redefining the same-named function after registering it does not change the callback. You either need to unregister, re-define the function and then register it again, or make the registered function an intermediary which calls another function,
[/left]
[left]EXAMPLE:
[/left]
[left]
[/left]
[left][color=blue]fn[/color] time_cb = print currentTime
[/left]
[left][color=blue]fn[/color] tcb = time_cb()
[/left]
[left]registerTimeCallback tcb
[/left]
[left]
[/left]
[left]In this case, the registered callback function, tcb, calls the real call back, time_cb, (by referencing the global variable it is defined in), meaning you can redefine time_cb() as often as you need and the callback will always invoke the latest definition. This is a useful technique to employ while you are developing and debugging a callback.
[/left]