Ignition Tag Count in a project

This will give you the total number of Ignition tags in a tag provider, and summarise them by different properties.
Run this in the script console, preferably directly on the GW server.

"""
Produces a summary of tags.
Example output:

Tag summary
========================
tagType: {'UdtInstance': 43, 'Folder': 95, 'AtomicTag': 644}
valueSource: {'memory': 197, 'opc': 391, 'reference': 1, 'expr': 47, 'derived': 2, 'db': 6}
dataType: {'Float4': 2, 'Int2': 3, 'DataSet': 43, 'Float8': 18, 'Int4': 295, 'String': 32, 'Int8': 27, 'Document': 3, 'Boolean': 221}
tagGroup: {'Default': 741, 'Alarm Summary': 18, 'ConfigTags_CMDPLCReset': 7, 'Value Change Triggers': 16}
"""

def getProviders():
	providers = system.tag.browse('')
	targetProviders = []
	for provider in providers.getResults():
		targetProviders.append(provider['name'])
	
	return targetProviders

providers = getProviders()

for provider in providers:
	# list of tag properties to include in the summary. Must be valid tag properties
	tag_summary_properties = ['tagType', 'valueSource', 'dataType', 'tagGroup', 'eventScripts', 'historyEnabled']
	query = {
		"options": {
			"includeUdtMembers": True,
			"includeUdtDefinitions": False
		},
		"condition": {
			"attributes": {
				"values": [],
				"requireAll": True
			}
		},
		"returnProperties": tag_summary_properties
	}
	
	print ''
	print 'Tag summary for provider "{}"'.format(provider)
	print "======================================================="
	tags = system.tag.query(provider, query)
	for tag_summary_property in tag_summary_properties:
		tag_summary = {}
		for tag in tags:
			if tag_summary_property in tag:
				if tag_summary_property == 'eventScripts':
					if tag['eventScripts'] is not None and tag['eventScripts'][0].get('enabled', True):
						temp = tag_summary.setdefault('eventScripts', 0)
						tag_summary['eventScripts'] += 1
				else:
					temp = tag_summary.setdefault(str(tag[tag_summary_property]), 0)
					tag_summary[str(tag[tag_summary_property])] += 1
		print '{}: {}'.format(tag_summary_property, tag_summary)

If you do end up using this, I wouldn't mind knowing what it returns :slight_smile:

1 Like