Assigning multiple values to Expression Array tag

If you set up and Expression tag with datatype “Float Array”, how do you set data to the different array index values?
I assumed that a comma was required, but Ignition balks at it.

Ignition also doesn’t want it set as like a case/switch, or using semi-colons.

There’s no special handling in the expression language for arrays right now, the value the expression evaluates to would have to be the whole array.

Kevin,
That seems to limit their usefulness if you can’t assign multiple values.
I assume this is also the case with the DATASET type?

Yeah. It’s not even clear to me what the syntax would be in either case - what were you imagining?

Expressions aren’t imperative like Jython scripting, they evaluate to a single value at the end, always. So it seems like you’d need to have an expression per array element. A single expression on the array itself somehow assigning values to the individual elements doesn’t make a lot of sense.

I guess using semi-colons or commas to separate each expression item?
Or maybe something like “[0] = expression;” then “[1] = expression;”
So you would be specifically setting the outcome of an expression to a particular element in the array.

But I see what you are saying: you would have to build a different expression window, because right now its single value output.

Expressions themselves are fundamentally single value output, and what you suggested is imperative assignment happening within an expression. Expressions don't generally have any side effects (the exception being runScript :scream:).

Not sure what the answer is here, but you're not wrong that arrays are a bit awkward (here, and elsewhere...)

I had an idea for this. There could be a makeArray expression function that accepts a variable number of parameter values and assembles them into an array after evaluating each parameter. Then you could assign an expression tag with an array datatype the result of this expression. The only trick would be ensuring the array ended up being the right datatype for the tag. All the sub-expressions would also have to be the evaluate to the same datatype as well or the resulting array type would widen to Object[] and fail to be assigned to the tag. There might also be problems in that there are more types in the tag system than the expression system uses (everything is Long or Double in expressions), so that would have to be solved too…

Hmmmmm :expressionless:

Sounds like a job for objectScript() and jython’s jarray module.

After a little bit of looking at what I wanted to use the grouped data for, I decided to use a UDT structure with pointers for month, day. I set it up to group 20 tags together, and it will work for what I was trying to do.
I will be blunt when I say that I don’t do very much scripting, as of yet.

Thanks for the ideas & suggestions!

I have managed to assigned multiple values to an expression tag using the runScript() function which calls a global script that returns multiple values.

For example, the tag expression on a string array expression tag could be;

runScript("shared.values.stringArray()")

The stringArray() function would look like the following;

def stringArray():
    values = []
    values.append("test")
    values.append("another test")
    return values

You can return as many values as needed for your expression tag.

Note that this will only work if the script function is in the global scope because the tag is defined within the global scope.

I initially discovered that this is possible in Ignition 7.9, however I have completed testing in Ignition 8 which confirms that this still works as long as you call a script function that is defined within the parent project of your current working project.

1 Like