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
    • Recent
    • Tags
    • Users
    • Login

    Catch if value is changed

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 451 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 06/01/2015 at 03:22, xxxxxxxx wrote:

      I have a res based ObjectData plugin with two buttons and a real input field. I am able to catch once buttons are clicked, but am unable to catch if real value is changed. Using the following code:

        
      BUTTON_HELP = 2001   
      BUTTON_INFO = 2002   
      REAL_VALUE     = 2003   
        
          def Message(self, node, type, data) :   
              if type==c4d.MSG_DESCRIPTION_COMMAND:   
                  if data['id'][0].id==2001: self._openHelpPdf();    # User clicked HELP Button   
                  if data['id'][0].id==2002: self._openAboutWin();   # User clicked INFO Button   
                  if data['id'][0].id==2003: print "Value changed"   # THIS DOES NOT WORK   
      

      So in order to catch if value is changed, should I be using some other MSG_DESCRIPTION command?

      Thank you.

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

        On 06/01/2015 at 06:28, xxxxxxxx wrote:

        Hi Tomas,

        Originally posted by xxxxxxxx

        So in order to catch if value is changed, should I be using some other MSG_DESCRIPTION command?

        You should use MSG_DESCRIPTION_POSTSETPARAMETER instead to check if a value has changed.

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

          On 06/01/2015 at 06:45, xxxxxxxx wrote:

          Thanks Yannick for response. However, I get error "TypeError: 'NoneType' object is unsubscriptable":

            
          REAL_VALUE     = 2003   
          def Message(self, node, type, data) :   
               if type==c4d.MSG_DESCRIPTION_POSTSETPARAMETER:   
               if data['id'][0].id==2003: print "Value changed"           # User changed value - DOES NOT WORK   
          

          All I want to do is check if value REAL_VALUE (assigned ID is 2003) does not exceed some value. That's why I try to catch if that value has been changed or not.

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

            On 06/01/2015 at 07:08, xxxxxxxx wrote:

            In the case of MSG_DESCRIPTION_POSTSETPARAMETER 'data' parameter does not hold any information, this is why you get an error. So it's not possible to know which parameter has been changed, you have to check all the parameters.
            If you need to validate values there's also MSG_DESCRIPTION_VALIDATE, but I don't think this will make a difference though.

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

              On 06/01/2015 at 15:02, xxxxxxxx wrote:

              Hello Tomas,

              it was mentioned on the python limitation list.
              But as a workaround this method will work. A variable which holds the values for comparison:

                
                def GetSliderValues(self, node) :  
                    data = node.GetDataInstance()  
                    self.a = data.GetReal(1012)#a slider  
                    return True  
                
                def DefaultValues(self, node) :  
                    data = node.GetDataInstance()  
                    data.SetReal(1012, 0.0)  
                    self.a = 0.0  
                    return  
                
                def Init(self, node) :   
                    self.GetSliderValues(node)  
                    return True  
                
                def Message(self, op, type, data) :  
                
                    instance = op.GetDataInstance()  
                  
                    if (type == c4d.MSG_DESCRIPTION_COMMAND) :   
                        id = data['id'][0].id  
                        if (id == 1101) :#a reset button  
                            self.DefaultValues(op)  
                              
                
                
                    if (type == c4d.MSG_DESCRIPTION_POSTSETPARAMETER) :  
                
                        if self.a != instance.GetReal(1012) :  
                            self.a = instance.GetReal(1012)  
                            print "changed to", self.a  
                
              

              Best wishes
              Martin

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