Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Handling MessageData.GetTimer() event

    Scheduled Pinned Locked Moved PYTHON Development
    10 Posts 0 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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=123454321

      class MyMsg(c4d.plugins.MessageData) :
        def GetTimer(self) :
            return 500

      def CoreMessage(self, id, bc) :
            if id==PLUGIN_ID:
                MyFunction()
            return True

      def 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.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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. ConfusedConfusedConfused

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 16/10/2016 at 10:44, xxxxxxxx wrote:

                  "Lost in translation" as is.:)

                  This code My target function   fires up 20 times per second with no matter of return value in GetTimer() method:

                  def GetTimer(self) :
                        return 500

                  and

                  def GetTimer(self) :
                        return 5000

                  and even

                  def GetTimer(self) :
                        return 50000

                  are giving the same result. Looks like a bug to me.
                  Don't you have such a problem on your PC?

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        On 17/10/2016 at 07:40, xxxxxxxx wrote:

                        Hi,

                        there's indeed a bug in the Python layer.
                        See related thread: here

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post