# Retrieving the UDT tag path from instance tag path

**URL:** <https://forum.inductiveautomation.com/t/retrieving-the-udt-tag-path-from-instance-tag-path/35810>\
**Category:** Ignition\
**Tags:** vision, ignition79\
**Created:** [June 18, 2020, 10:27pm UTC](https://forum.inductiveautomation.com/t/retrieving-the-udt-tag-path-from-instance-tag-path/35810 "2020-06-18T22:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 18, 2020, 10:27pm UTC](https://forum.inductiveautomation.com/t/retrieving-the-udt-tag-path-from-instance-tag-path/35810/1 "2020-06-18T22:27:55Z")

</div>

I’m looking for how to retrieve the tag path of the UDT definition to which a tag belongs to, within an instance of the UDT.

I’m sure I’ve done this before but having a mental blank…

For example, I want to return ‘Packaging/Filtration/Devices/Filler’ from below, given the tagPath for the ‘Filtration Status’ tag.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/57338d0360e3fa31317437a4c4ed86a446303ca4.png)

---

<div class="post-metadata">

**Author:** ![roger\_larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roger_larson/32/8574_2.png) [@roger\_larson](https://forum.inductiveautomation.com/u/roger_larson)\
**Post date:** [June 19, 2020, 12:39am UTC](https://forum.inductiveautomation.com/t/retrieving-the-udt-tag-path-from-instance-tag-path/35810/2 "2020-06-19T00:39:28Z")

</div>

I’m assuming you are in Ignition v7.9.x, but you might be able to do something like this:

```auto
tagPath = "[default]Path/To/Tag/Line 2/Filler.typeId"
typeId = system.tag.read(tagPath).value
print typeId

```

I don’t have 7.9 on-hand to test that out, but I am curious as to the solution.

I found that in Ignition 8.0, this seemed to work:

```auto
tags = system.tag.getConfiguration(tagPath)
for tag in tags:
	tagType = tag['tagType']
	if str(tagType) == 'UdtInstance':
		typeId = str(tag['typeId'])
	    print typeId	

```

Cheers,  
Roger

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 19, 2020, 1:54am UTC](https://forum.inductiveautomation.com/t/retrieving-the-udt-tag-path-from-instance-tag-path/35810/3 "2020-06-19T01:54:03Z")

</div>

Thanks for the prompt! You can get the `typeId` in 7.9.14 from browseConfiguration.  
Function to get the UDT definition tag path below:

```auto
def getUDTTagPath(tagPath, recursion=0, sRet=None):
	# if we recurse more than 20 times, kill it!
	if recursion > 20: raise NameError("Too many recursive calls made!")
	
	# get the parent folder name and its configuration, so that we can check if the tag we passed in is a UDT_INST
	parentTagPath = "/".join(tagPath.split("/")[0:-1])
	tagName = tagPath.split('/')[-1]
	tagsConfig = system.tag.browseConfiguration(parentTagPath, 0)
	
	for tagConfig in tagsConfig:
		cfgTagName = tagConfig.getName()
		if cfgTagName == tagName:
			tagType = tagConfig.getTagType()
			if str(tagType) == 'UDT_INST':
				for prop in tagConfig.getProperties():
					if str(prop) == 'typeId':
						# we found the UDT definition tag path, return it
						sRet = tagConfig.get(prop)
						return sRet
			else:
				# the current tag element is not a UDT_INST, so try the parent 
				sRet = getUDTTagPath(parentTagPath, recursion+1, sRet)
	return sRet

```
