Write to UDT property with tag change script

I am developing a UDT for a weigh scale that reports its units as an integer. So there is an OPC tag called ReportedUnits which is an integer, interpreted as follows:

0 = g
1 = kg
2 = t

I have an expression tag simply called Units that converts this integer into the relevant string:

switch({[.]ReportedUnits, 0, 1, 2, "g","kg","t","")

I would then like to bind this “Units” tag to the EngUnit parameter of all other weight-related values within my UDT, so that any time I see a weight, it’s shown with the units that the weigh scale is actually using. However, as I understand it, I can’t directly bind a UDT member parameter to another UDT tag value (please correct me if this is possible as it will solve my problem in a far easier way).

I know that I can bind a UDT member parameter to a UDT parent parameter, so if I had a UDT parameter “Units”, I can easily bind all my weight value EngUnit to that. But then, I just need to make sure that the UDT parameter updates if my weigh scale units change.

I found another thread that mentioned I can write to a UDT parameter, but did not specify how. I assume I need to use system.tag.writeBlocking but I can’t work out what my path would be. Can anyone help me out with the path (or an easier way to achieve my end goal)?

Easiest way to get the parameter path is to drill into the UDT with the tag browser, right click the parameter and select copy path.
image

Thanks, but this is within a UDT definition so it needs to be dynamic - I need to work out how to extrapolate the path to the parent UDT parameter from a UDT element tag change script.

You would need to build the string then, If you have good organization and naming conventions that shouldnt be too bad.

Yes, that’s what I’m seeking some assistance with

We create expression tags in all of our UDTs to expose meta information.
Just add an expression tag called MetaTagPath and set its Expression to {PathToParentFolder}

1 Like

Thanks, that’s a great starting point. I wasn’t aware of the {PathToParentFolder} property!