UDT in script

Is there a way to access UDT properties inside a script. Basically I want to pass a UDT as a parameter in a script so I could check the properties and do some logic…

Instead of doing this

def getStatus(tagPath):
        import system
	exist = system.tag.exists(tagPath)
	if exist:
		fault = system.tag.read(tagPath + "/Fault").value
		vfdFault = system.tag.read(tagPath + "/VFDFault").value
		pe1 = system.tag.read(tagPath + "/PE1").value
		pe2 = system.tag.read(tagPath + "/PE2").value
		running = system.tag.read(tagPath + "/Running").value
		inbound = system.tag.read(tagPath + "/Inbound").value
		outbound = system.tag.read(tagPath + "/Outbound").value

                #Do some logic

I’ll just have to do this

       def getStatus(udt):
                if udt.fault:
                   return 0
                elif udt.vfdFault:
                   return 1
                #.......... and so on


No, the only way to get a UDT object is by having a property with the UDT datatype somewhere on the window. You can’t get the UDT object through scripting right now.

Thanks Travis…

Is it still not possible to access a UDT object from a script?

I assume that since ignition can grab a UDT tag and pass it as a parameter, there must be a function (albeit hidden) that can take a tag path and return an list object that contains the UDT values. Does anyone know what this function would be called?


Give this a whirl

def getAllTheTagz(udtPath):
	tagPaths = [tag.fullPath for tag in system.tag.browseTags(parentPath = udtPath, recursive = True) if not tag.isFolder() and not tag.isUDT() ]
	_results = system.tag.readAll(tagPaths)
	theTagz = {}
	for i in range(len(tagPaths)):
		theTagz[str(tagPaths[i][len(udtPath):])] = _results[i]
	return theTagz
myUDT = getAllTheTagz("[provider]path/to/the/udt")
print myUDT["propertyPath"].value

You can then access the values in an easy manor, such as the last line. If you only need the values, change the _results[i] in the for loop to _results[i].value

1 Like