Create list of tags to use for tag history query

Whats the best way to create a list of tags I can use for tag history query that will allow me the ability to dynamically do the query so additional tags may be added but i won't have to change the code.

I currently created a list with tag paths manually:

	tagpaths = ['[PLC]AnalogInputs/FT101/InputValue', '[PLC]AnalogInputs/FT201/InputValue',
		'[PLC]AnalogInputs/PT200/InputValue', '[PLC]AnalogInputs/TT200/InputValue',
		'[PLC]AnalogInputs/TT201/InputValue', '[PLC]AnalogInputs/VT101/InputValue',
		'[PLC]AnalogInputs/VT201/InputValue', '[PLC]AnalogInputs/VT202/InputValue']

I want to be able to iterate through a tag folder, find each UDT tag, and then create this list with all of the UDT's present in the folder.

Here are the tags I want to go through in the AnalogInputs folder.

I have tried using system.tag.browse to try to create this list but can't get it to work.

If you post your code we could try to find where you went wrong.

Regardless, here is a quick example of a function that does such a thing:

def getTagPaths(path):
	fltr = {'tagType': "UdtInstance"}
	tags = system.tag.browse(path, fltr)
	return [str(tag['fullPath']) + "/InputValue" for tag in tags]
1 Like

Awesome! Took your example and implemented directly

One question I had was about the filter. I am trying to understand why this part is needed?

Here are the results:



Ah I see. This filters out any tag that is not a UDT tag. In my case every tag in the folder is a UDT tag therefore I don't necessarily need it but if I did add a tag within that folder that wasn't a UDT tag it could cause issues...thanks!

1 Like

You could also specify what type of UDT you want:

filter = {
    'tagType': "UdtInstance",
    'typeId': "your_udt_name"

In case other types of UDTs ever get added to that folder.