UDT how to get ParentFolder from PathToParentFolder parameter

I’m trying to figure out how to best create a paramterised UDT that automatically selects the OPC Server based on the folder that the instance of the UDT resides in. I am aware of the predefined {PathToParentFolder} parameter, but what I want right now is effectively a {ParentFolder} parameter. This is because my current ideas of tag organization are:

       |    |- UDT Instance
       |    |- UDT Instance

I believe that the {PathToParentFolder} will give me “\Devices\Device1” etc as it defined as:

The full path to the folder that this Tag is in.

when what I want is simply “Device1” as I am planning on a series of OPC UA connections called Device1, Device2 … etc.

Is there anyway to do what I want?

My fall back is to eliminate the top level folder, but keeping that folder fits in with other patterns I want to following in order to best organize things.

Just to confuse things a bit, I just created a UDT with a string tag inside of it, and set the value to be {PathToParentFolder}, and the result was surprising. It was:

Devices/Device1/UDT InstanceName

Which is technically correct if you treat the instance as another level of folder. But this is not what I was expecting. So what I thought of as the parent is not the parent.

You can use parhtoparentfolder in conjunction with the split and len function to pull out the last item in the path structure (i.e. the parent folder name). It’s a bit of a mess… But you can use:
split({PathToParentFolder}, '/')[len(split({PathToParentFolder}, '/'))-1, 0]

I haven’t tested…but have used something similar in the past

1 Like

Where in the UDT should I be inserting such an expression? I have been experimenting with memory string stags inside UDTs and trying to set the value to the results of various formulas (and via values of parameters) and have been totally failing. I can get values like {1+1} successfully giving 2, but anything involving string manipulation (even simple concatenation) isn’t working.

Hmm, actually it doesn’t look like the expression language is supported in the opc path keys, which means you’re probably out of luck…

I was slowly coming to that conclusion, but wasn’t sure if it was me or ignition. I’ll just have to settle with fixed configuration values.