'Error expanding parameter reference' in Tag Event script when using curly braces

Using pythons string.format placeholders in a tag event scripts collides with Ignitions parameter references in 8.1.0. There are workarounds, but i spent some time before i found the cause of the script error. Maybe there should be a warning in the manual about using curly braces in tag event scripts.

I never realized that parameters in curly braces are supported in tag event scripts. Is this a new feature in 8.1?

The script

test='{0} {1}'.format(tag, tagPath)

shows the error

Error expanding parameter reference
java.lang.NullPointerException

You're using Python 3 syntax, whereas Ignition uses Jython 2.7 which doesn't support the formatfunction. You need to use the 2.7 method, e.g.:test=’%s %s’ %(tag, tagPath)`
I stand corrected… I thought this was added in 3, but turns out it was 2.7
In any case, you can use the old method to work around the issue

There is still the problem that curly braces are also used for dictionaries in python {'init1': 1, 'init2': 2}.
Maybe not commonly used in tag event scripts, but imho parameter replacement in script sourcecode is not a good idea, especially when it is not documented.

If I remember the timeline correctly, automatic parameter expansion was a “feature” in 7.9 and previous, then deliberately omitted in early 8.0.X versions in favor of an explicit syntax…then added back in after backwards compatibility complaints.

There’s no winning, here.

The best way to avoid this particular issue is to move the code into a script module and delegate from the tag event.

1 Like

Since parameters are dynamic in 8.x, does that mean the script runs through parameter replacement and is recompiled on every single invocation and seperately for every UDT instance?

Not a clue :slight_smile: - @ggross may know?

I totally missed the documentation for the legacy curly bracket approach, so please ignore my complaints about missing docs. That info also answers my above question.

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.

1 Like