Create a Script Function to Evaluate an expression.
c
cbohon
I am trying to evaluate some "Expression Language" expressions in a script. But I dont see a good way to do this. Could you add a scripting function to do this? Something like:
system.util.evaluateExpression(expressionString, [tagPathString])
returns value
Log In
Kathy A.
Can you give us a use case? Most expression functions are also available as script functions.
c
cbohon
Kathy A.: If I want to find out current settings of all the alarms in a script, I can use a couple of different functions to get a list of all alarms and their current settings, but the expressions are not evaluated. I'd like to evaluate the expressions so that I have a list of current settings.
Another idea would be to put an optional boolean input for functions that might return an expression, like system.tag.getAlarmStates, to give the option of returning a tuple with the expression, and the current value of the expression.
O
Oleg M
Kathy A.: I am voting in support for this feature, since it would provide a good work-around for the single component property binding limitation. Suppose, we have a lot of similar components of the same type, whose property value depends on the same expression, e.g. a complex pipeline, consisiting of lots of segments, whose state depends on the set of adjacent valves. Introducing a new valve would require a lot of manual work changing the property bindings for every single segment. If we had smth like the "evaluateExpression" method, we could simply introduce a new custom property, holding the expression string for every pipe segment, and a script that runs every time, when the custom property gets updated. Now we could select multiple components that has the same (custom) property to change that property at once!
J
Joe Friedrich
Kathy A.: I just want to create a qualified value. That functionality is not (currently) available in scripting. (The reason I want to create a qualified value is in order to automate testing.)
P
Paul Griffith
Joe Friedrich: You absolutely can create a QualifiedValue in scripting; something like this:
from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue, QualityCode
qv = BasicQualifiedValue("someValue")
qv2 = BasicQualifiedValue("someValue", QualityCode.Bad_Failure)
qv3 = BasicQualifiedValue("someValue", QualityCode.Bad_Stale, system.date.now())
c
cbohon
tagPathString would be an optional argument to give the script correct context when needed. It would point to the tag that has the expression binding on it.