Dynamically add component to Root Container

Found a way to add UDT’s to it, it needs to be done async, to ensure templates are created before assinging the UDT values:

def getUdt(tagpath, template)
	from com.inductiveautomation.ignition.common.sqltags.parser import TagPathParser
	from com.inductiveautomation.factorypmi.application.binding import UDTProperty
	parser = TagPathParser()
	print type(parser.parse(tagpath))
	udt = UDTProperty(parser.parse("Path/To/UDT/Definition"))
	udt.initialize(component, "ST_Motor", component.parent.appContext)
	udt.setDrivingTagPath(parser.parse(tagpath)) 
	print type(udt)
	return udt

# assign UDT's in async way to ensure templates are loaded before assignment
def assignUdts():
	for tag in system.tag.browseTags(parentPath = tagFolder, sort="ASC"):
		# all templates were called after their tag names, so get them by tag name
		tmp = container.getComponent(tag.name)
		udt = getUdt(tag.path, tmp)
		tmp.ST_Motor = udt
system.util.invokeLater(assignUdts, 5000)

Some things are still hard-coded, but at least it works now.

1 Like