Expression Binding Help - Passing list/array/sequence as an argument to a Python Script

I am attempting to run a scrip function in a expression binding. My python function accepts two arguments, both which need to be a list.

Example:
def check(tag1,tag2):
do something
return(some string)

tag1 are ints and tag2 being strings

Expression Binding Language:
runScript(“project.check”,0,[1,1],[‘string1’,‘string2’] )
//This don’t work is it possible to make list in expression language
//I know it possible in latest version of ignition but we are working in prior version.

Your syntax is not correct. You may want to pass list or arrays as encode strings.

runScript(“project.check”,0,"[1,1]","['string1','string2']")

Then decode as real object with

import ast
values = "[1,1]"
paths = "['string1','string2']"
values = ast.literal_eval(values)
paths = ast.literal_eval(paths)

It might be easier to use a script transform, maybe with an expression structure binding.

edit - ah, didn’t see you’re on 7.9. I don’t know anything about 7.9.

I haven’t tried it yet but this should work. But since my strings are in tag paths I would need to use a system.tag.read () to get the string. Thanks

Consider using my objectScript function (from Simulation Aids) instead of runScript. runScript() only passes extra expression arguments when the first (string) argument evaluates to a python function.

My objectScript() accepts any python expression as a string, and delivers expression arguments in a local variable. Which means your python expression can listify your arguments without relying on the stringification of your lists. Your attempt with runScript would become this:

objectScript("project.check([args[0], args[1]], [args[2], args[3]])",
	1, 1, 'string1', 'string2')

If project.check accepts list-like objects (such as tuples), not just true lists, that can be simplified with slicing:

objectScript("project.check(args[:2], args[2:])",
	1, 1, 'string1', 'string2')
1 Like