Execute Script Transform on Binding Even When Tag Does not Change

Is there a way to cause a Script Transform to execute on a Perspective property even if the underlying data for the binding has not changed? For example, we have a gauge component in Perspective that is tied to a tag. The tag itself may be at 0, but the lowest value in the gauge itself may be a different number, such as 36. I am using a script transform to tell the needle to point to 36 if the value of the tag is below 36.

My problem is that if I change the lowest value on the gauge itself, such as to 38, the needle doesn’t adjust because the underlying tag hasn’t changed and the transform hasn’t executed. I have tried to use the refreshBinding() option, but it appears that this doesn’t work because the component merely looks at the unchanged tag again and doesn’t execute the transform.

Any ideas how to resolve this?

Gauge Correct
GaugeCorrect

Gauge Incorrect
GaugeIncorrect

If I’m reading what you want right, I’d create a custom property that you bring your tag value into. Then I would use an expression binding on the “value” property. For my example I called my custom property tagVal. The expression will update when any of its variables update instead of just when the main value triggers the transform.

if({this.custom.tagVal}<{this.props.outerAxis.minValue}
	,{this.props.outerAxis.minValue}
	,{this.custom.tagVal})

Building upon this response, store both the value of the min value and the value into separate custom properties. Then define a third property for the actual gauge value that uses an expression structure binding attached to both of the other properties. In this way, if either property changes, the property tied to the gauge itself will always change.

Thanks! This helps!

Thank you!

Late to the party, but I'm just curious why the refreshBinding() doesn't work in cases like this? Shouldn't it execute the binding again, causing the script transform to execute and returning the expected value? Even if the value of whatever the property is bound to doesn't change?

refreshBinding almost certainly does tell the tag binding to re-evaluate. However, the tag binding is probably 'smart enough' to know that no change was made and thus doesn't emit a new value to the transform system. I would consider whether refreshBinding will force a re-evaluation of an unchanged value "undefined behavior" - it may change from version to version of Ignition, because it's an edge case that's not sufficiently defined. Using an expression structure binding to make it explicitly clear which values can feed in to the expression is absolutely the better pattern for this specific use case.

1 Like

The option proposed by @bpreston in this case worked great for me.

1 Like