UDT Parameters in Tag Event Scripts
Parameters on UDTs can be interacted with from Tag Event Scripts. There are two main approaches.
Modern Approach
As of 8.0.7, parameters values can be accessed as dictionary values. The benefit of this approach is that value changes to UDT parameters will be reflected in subsequent calls. In most cases, this modern approach is preferable. Thus, if the script needs to access the most recent parameter values on a UDT, and the parameters can change through a means other than editing the UDT (which would restart the tag), then this approach should be used.
If trying to access the value of a parameter named "myParam" from a Tag Event Script within the UDT, the script would look like:
Code Block |
---|
# Reminder: "tag" is a built-in argument on all Tag Event Scripts. Accessing the "parameters" key on the tag argument will
# provide access to all UDT parameters.
paramValue = tag['parameters']['myParam'] |
Legacy Approach
In 7.9 and prior, UDT parameters could be access in Tag Event Scripts with the familiar curly brackets approach. Thus, if trying to access the value of a parameter named "myParam" from a Tag Event Script within the UDT, the script would look like:
Code Block |
---|
paramValue = {myParam} |
A large caveat with this approach is that value changes made to the parameter ("myParam", in the example above) would not be reflected in scripts until the UDT was restarted. UDT parameters are pre-compiled, which in this case means value changes are mostly ignored until the UDT is restarted.
In all cases, the modern approach above is preferred.