# Dynamically read tags inside of a UDT from a script

**URL:** <https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 15, 2017, 6:51pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534 "2017-06-15T18:51:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wfallon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wfallon/32/3773_2.png) [@wfallon](https://forum.inductiveautomation.com/u/wfallon)\
**Post date:** [June 15, 2017, 6:51pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/1 "2017-06-15T18:51:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [June 15, 2017, 11:09pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/2 "2017-06-15T23:09:31Z")

</div>

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.

```auto
	# 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

```

---

<div class="post-metadata">

**Author:** ![wfallon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wfallon/32/3773_2.png) [@wfallon](https://forum.inductiveautomation.com/u/wfallon)\
**Post date:** [June 16, 2017, 11:30am UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/3 "2017-06-16T11:30:34Z")

</div>

Thank you, this does what I need perfectly.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 23, 2023, 7:56pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/4 "2023-05-23T19:56:56Z")

</div>

Now that `system.tag.browseTags()` is deprecated, I'm looking for a solution that uses the new `system.tab.browse()` function.

I have a couple instances of a UDT and I want to reach all of the members via scripting.

---

<div class="post-metadata">

**Author:** ![CalebM](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CalebM](https://forum.inductiveautomation.com/u/CalebM)\
**Post date:** [May 23, 2023, 8:25pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/5 "2023-05-23T20:25:04Z")

</div>

I believe this works the same as the one David provided, just changed it to use the new `system.tag.browse()`

```auto
# Get a list of tags in the folder or UDT
tags = system.tag.browse(folder, {"recursive":True, "tagType": "AtomicTag"}).getResults()

# Create a list of tag paths
paths = []
for tag in tags:
	paths.append(str(tag['fullPath']))

# read the tags all at once
vals = system.tag.readBlocking(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

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 23, 2023, 8:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/6 "2023-05-23T20:40:31Z")

</div>

The syntax for `system.tag.browse()` is entirely different. But I don't actually need to use it in this case (yet).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 23, 2023, 10:11pm UTC](https://forum.inductiveautomation.com/t/dynamically-read-tags-inside-of-a-udt-from-a-script/14534/7 "2023-05-23T22:11:34Z")

</div>

The `jsonValues` meta node works for folders and UDT instances and gives you an automatic recursive view of all the tags inside of a UDT:  
So from a structure like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/438c5ccc07d6e4fab425d939794b5630051075b8.png)

You can read the folder:

```python
from pprint import pprint
v = system.tag.readBlocking("[default]udts.jsonValues")[0].value
pprint(v)

```

```json
{
    "beetles": {
        "george": 4,
        "john": 1,
        "paul": 2,
        "ringo": 3
    },
    "ducks": {
        "dewey": 3.14,
        "huey": 123,
        "louie": "abc"
    },
    "family": {
        "folder": {
            "fourInstance": {
                "george": 4,
                "john": 1,
                "paul": 2,
                "ringo": 3
            },
            "threeInstance": {
                "dewey": 3.14,
                "huey": 123,
                "louie": "abc"
            }
        },
        "fourInstance": {
            "george": 4,
            "john": 1,
            "paul": 2,
            "ringo": 3
        },
        "threeInstance": {
            "dewey": 3.14,
            "huey": 123,
            "louie": "abc"
        }
    }
}

```

Or any UDT instance inside:

```python
from pprint import pprint
v = system.tag.readBlocking("[default]udts/beetles.jsonValues")[0].value
pprint(v)

```

```json
{
    "george": 4,
    "john": 1,
    "paul": 2,
    "ringo": 3
}

```
