Catch if value is changed
-
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.
-
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.
-
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.
-
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. -
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