Retrieving the UDT tag path from instance tag path

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.

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

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:

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

Cheers,
Roger

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

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
1 Like