Tag browse function using UDT child tag

I am using the system.tag.browse to search recursively a specific UDT instances in my tag directory. The UDT I want to find has a memory tag defined with a string value. I would like to use the browse function to get the path to all the UDT’s with a specific name and a specific value in that tag. So I am wondering if it is possible to set in the browse function a value that a child tag of the UDT must match in order to retrieve the UDT’s path? Or is it something that can not be done within the function and must be filtered outside of it using a loop?

Thanks in advance!

I believe you'll need to first use the browser function to retrieve a list of all the tags matching your UDT datatype, then loop through those to generate a list of all the tags you want to read. Then do a single readBlocking call to read them all at once and loop through those values to build a new list of tags that have the matching value you're looking for.

2 Likes

After Tag Browse, use a for Tag in Tag_Paths to parse what you need. I have some examples here where I was working through something similar.

As others have said, you’ll have to browse for the UDT Instances first, and then filter those based on the value of the tag that you want to look at.

Something like this:

#filter to find UDTInstance of your UDT
tagFilter = {'typeID':'YourUDTName','tagType':'UDTInstance','recursive':True}

#adds the member tags name to the end of the UDT path
paths = [str(result['fullPath']) + '/memberTagName' for result in system.tag.browse('Starting\Tag\Path',tagFilter).results]

returnPaths = [path[:path.rfind('/')] for path,qv in zip(paths,system.tag.readBlocking(paths)) if qv.value == 'yourStringValue']

After execution returnPaths will have a list of paths to all of yourUDTName instances within Starting\Tag\Path where the value of memberTagName is equal to yourStringValue

CAUTION: This is a recursive function and should not be run on the EDT in Vision, or in Tag Value Change Events.