Good day,
I have tried to write the scripts in Script Editor that contain next functions:
concat("part_path_A", "part_path_B")
toStr(2)
while "concat" and "toInt' has worked perfectly in expression functions, I had been disappointed that I can't use them in script editors.
This force me to write super longue code (almost 100 lines) manually by listing all possible combinations inbetween "part_path_A", "part_path_B" and also there is some number inbetween them. I shell convert this number (I can take it from memory tag or pass it as parameter to graphic object) to string before combine
Is there any way to do it (such combination of strings) by usage of other existing functions, that do works well in Script Editor of graphic component in Vision?
Thank you very much in advance,
Good day, Transistor, PGriffith, Irose,
Thank your for your replies.
It has actually helped.
I didn't know that
result = "part_path_A" + "part_path_B"
would actually work.
However, if I can't use functions that do transform numbers to string, it will help me just a little bit.
I have tried "toStr", that works in expressions.
Am I wrong with syntaxis? Is there another function?
I need to simplify this to avoid having hundreds of lines. I have different combinations of numbers after M and after Tab, that comes as parameters.
It is resolved.
I have found that I should just use function "str", and I works.
I had been confused a lot because expression functions that we have to use while writing expressions are not the same as somebody should use for Script writing in graphic objects.
Scripting is a full programming language based on Python 2.7.
Expression Language is more like an Excel formula. You can't write a program with it - just an expression that returns a value. It can't write to another object.
The system.tag.readBlocking function takes, as its first parameter, a list of tag paths. So you can just add all of the tag paths into a list and pass that in. The returned Qualified Values will be a parallel array in the order that you supplied the tag paths.
Just don't break the paths out with unpacking like I did in my example (to keep consistency with your script).
So, instead of:
path0, path1, path2, path3, path4, pathR = [
"[Bande]M{}/Tab1/SomeX_LB{}".format(MKey, i)
for i in xrange(5)
]
Do something like this:
paths = [
"[Bande]M{}/Tab1/SomeX_LB{}".format(MKey, i)
for i in xrange(6)
]
values = system.tag.readBlocking(paths)
# optionally, unpack to separate variables:
v1, v2, v3, v4, v5 = [qv.value for qv in values]
Note the comment from @rperretta about the return value from readBlocking - it's a list of qualified value objects, so if you just care about the value attribute you need to extra it.