Dynamically read tags inside of a UDT from a script

Hi,

I want to read tags in a UDT dynamically from a script.

For example, if there are 4 tags in a UDT, I want to be able to put those in a list with the same code if there were 3.

Thanks.

Hi wfallon,

Not quite sure what you are trying to do, but maybe this will help.
It reads all tags in a folder or UDT and saves them to a dictionary.
Just modify it to suit your needs.
You just need to specify the folder path.

	# get a list of tags in the folder or UDT
	tags = system.tag.browseTags(parentPath=folder, recursive=1, sort='ASC')
		
	# Create a list of tag paths
	paths = []
	for tag in tags:
		paths.append(tag.fullPath)
				
	# read the tags all at once
	vals = system.tag.readAll(paths)

	# store the values in a dictionary
	values = {}
	for x in range(len(paths)):
		length = len(paths[x]) - len(folder)
		name = str(paths[x])[-length:]
		# add each tag to a dictionary
		values[name] = vals[x].value
1 Like

Thank you, this does what I need perfectly.