Returning Text and Dynamic values in a String

I am trying to create a transform in a label that will display multiple strings depending on a tags value. The strings contain text and dynamic values (tags). When I search the internet, I find that the return f"" format should work to return text and dynamic values in the same string, but it does not. I'm on version 8.1.42 working in perspective. Can anyone tell me what I'm doing wrong?

That's likely a Python 3 syntax. Jython is equivalent to python 2.7, so you'll need to do string with {0} replacement.format(L1) or string with %0.2f replacement % L1

f formatting is for Python3. Ignition uses Jython 2.7 - so you’ll need to go with %s or .format().

return ‘The value is %s‘ %L1

Other things of note, avoid doing blocking reads in a transform. Bind the tags you want to monitor to custom properties, either on the component or the root container of the view. From there, you can reference them in an expression, no transform needed.

In general, you should be aiming to try to achieve things with only expressions, especially simple tasks such as this. Expressions are much more performant than script transforms.

an example expression would be

if(
	{path.to.driver.tag} = 5,
	stringFormat(
		"the value is %0.2f", 
		{path.to.custom.prop.bound.to.tagA}
	),
	"22"

if you have multiple states on your driving tag, it may be better to use a case statement instead.

3 Likes

Thank you. I will try your suggestions.

I tried you suggestion and it took care of the error. Thank you, but I am getting back more information than just the value. The information is coming from a PLC tag and it looks like status and a timestamp are coming back also. Any way to stop that?

image

Use L1[0].value, the system function returns a list of qualified values.

If you haven't already, start working through inductive university. Its free and covers a lot of things, and its from inductive automation(the people who make Ignition.)

Thank you Ryan, that worked!