Undo tag writes and restore old value

Hi everyone,
i need to check a value tag written in a numeric text box on a window (vision).
I want to save the value of the tag and check what the user inputs ; I need to be able to undo the tag changes and write back the old value and refresh the textbox…
what is the best way to accomplish this ??

thanks in advance,

Im assuming that you cant use the useBounds of the numeric text box.

So it depends on how often you need to do it. If it is just a few times then you can take care of this in the propertyChange script of the components. Much more then that and you’ll need a more centralized method.

I would create a shared/project script utility to enforce your limits, something like the following:

def commitTagWrite(self, tagPath, newValue, oldValue, lowLimit, highLimit):
     if newValue:
          if newValue != oldValue and newValue >= lowLimit and newValue <= highLimit:
               return True
     return False

On the component, do not bind directly to the tag. Instead, in the scripting do something like this:

if event.propertyName == 'value':
     if not project.scriptName.commitTagWrite('your tag path',event.newValue, event.oldValue, 0,100):
          event.value = oldValue

It may be worth adding a custom property to the component/template to hold the tagPath so it isn’t hard coded, but again that is dependent on how many times you need to do this.

This would write the new value if it was between 0 - 100, the oldValue if it was outside those limits, and do nothing if the newValue is None.

You can also wrap all of this in a Try/Except block and use a Logger for various things. Probably not a bad idea especially if you have several of these to do.

Of course there may be a better way of accomplishing the task that I am not aware of.

1 Like

Instead of binding the tag directly to the entry field’s editable property, bind it to a custom property–I like to name such properties Raw. Then uni-directionally bind the editable property to the raw property. I also like to make another property named Dirty with an expression comparing Raw to editable property. Then you can style the component based on whether it matches the current tag value. When you do this use separate “Save” and “Cancel” buttons. The former would write to the tags with the edited value, and the latter would copy the Raw property value over the editable property.

1 Like

Hi guys
thankyou for your time…will proceed with your suggestions.

best regards