Handling MessageData.GetTimer() event
-
On 15/10/2016 at 17:29, xxxxxxxx wrote:
Hi everyone.
I'm trying to create timer that runs a function twice a second.Here's the code of my plugin:
import c4d
from c4d import plugins
PLUGIN_ID=123454321class MyMsg(c4d.plugins.MessageData) :
def GetTimer(self) :
return 500def CoreMessage(self, id, bc) :
if id==PLUGIN_ID:
MyFunction()
return Truedef MyFunction() :
print "tick"if __name__=="__main__":
plugins.RegisterMessagePlugin(PLUGIN_ID, "TestPlugin", 0, MyMsg())I can't figure out how to create and handle timer event. Is it possible? What am I doing wrong.
Would appreciate any help.
Have a nice day. -
On 16/10/2016 at 07:15, xxxxxxxx wrote:
Try it like this
import c4d from c4d import documents, plugins PLUGIN_ID = 1000000 class MyMessage(plugins.MessageData) : def __init__ (self) : self.object = None def GetTimer(self) : return 500 def CoreMessage(self, id, bc) : if id == c4d.MSG_TIMER: print "Timer Executed" #<---Put the call to your function here return True if __name__ == "__main__": plugins.RegisterMessagePlugin(id=PLUGIN_ID, str="Message Plugin", info=c4d.PLUGINFLAG_SMALLNODE, dat=MyMessage())
-ScottA
-
On 16/10/2016 at 09:41, xxxxxxxx wrote:
Thanks a lot, Scott, but there is 1 problem with the code you gave me: Event fires up about 20 times per second, not twice. Should I check the time manually, or what?
*There's not a single word about "c4d.MSG_TIMER" in Maxon's python documentation.
-
On 16/10/2016 at 10:09, xxxxxxxx wrote:
The GeTimer() executes in milliseconds.
Change return 500 to whatever value you want.
Try something like 2000 for starters.There's an example of this in the C++ docs.
Sometimes the answer to a Python question can be found in there.-ScottA
-
On 16/10/2016 at 10:18, xxxxxxxx wrote:
Scott, I'm afraid you didn't understand me. Please pardon my english - it's not my native language.
Let me repeat myself: YOUR code (with "return 500" statement) fires up about twenty times per second. Is it bug?*R17.053
-
On 16/10/2016 at 10:30, xxxxxxxx wrote:
Hopefully this will be clearer.
import c4d from c4d import documents, plugins PLUGIN_ID = 1000000 class MyMessage(plugins.MessageData) : def __init__ (self) : self.object = None def GetTimer(self) : timerValue = 2000 #<--- Change this value to change how long to wait between executions return timerValue def CoreMessage(self, id, bc) : if id == c4d.MSG_TIMER: print "Timer Executed" #<---Put the call to your function here return True if __name__ == "__main__": plugins.RegisterMessagePlugin(id=PLUGIN_ID, str="Message Plugin", info=c4d.PLUGINFLAG_SMALLNODE, dat=MyMessage())
-ScottA
-
On 16/10/2016 at 10:44, xxxxxxxx wrote:
"Lost in translation" as is.:)
This codeMy target function fires up 20 times per second with no matter of return value in GetTimer() method:def GetTimer(self) :
return 500and
def GetTimer(self) :
return 5000and even
def GetTimer(self) :
return 50000are giving the same result. Looks like a bug to me.
Don't you have such a problem on your PC? -
On 16/10/2016 at 11:04, xxxxxxxx wrote:
Working properly for me in R13.
Increasing the timer value makes it wait longer between executions as expected.Are you running this in the script manager?
The code I posted is a plugin. The code should be saved in a .pyp file and then place in the plugins folder.-ScottA
-
On 16/10/2016 at 11:12, xxxxxxxx wrote:
LOL. Of course I'm running this code as a plugin. I think that it's a little bug in R17 and combining this code with the c4d.GeGetTimer() gonna give me the desired result.
Anyway thanks a lot - you really helped me very much.UPD: I've sent a bug report about this problem.
-
On 17/10/2016 at 07:40, xxxxxxxx wrote:
Hi,
there's indeed a bug in the Python layer.
See related thread: here