And, if you want to read a selection of properties from tags, I use this below. You could merge this into the script above to read all of the history properties of the tags found.
# Date: 2022-10-19
"""
Description:
Finds tags and reads a list of properties for them. Returns a CSV of tagPaths and their property values into the clipboard.
"""
# SETUP
REMOVE_TAGS_IN_UDTS = True # set to True to remove tags found that are inside of UDT instances
path = '[default]' # the tag path to search for tags in
readProps = [] # the tag properties to read
readProps.append('opcItemPath')
readProps.append('enabled')
readProps.append('engUnit')
readProps.append('formatString')
readProps.append('scaleMode')
readProps.append('engLow')
readProps.append('engHigh')
readProps.append('rawLow')
readProps.append('rawHigh')
readProps.append('scaledLow')
readProps.append('scaledHigh')
######
tags = system.tag.browse(path = path, filter={'recursive': True, 'tagType': 'AtomicTag'})
if REMOVE_TAGS_IN_UDTS:
udts = system.tag.browse(path=path, filter={'recursive': True, 'tagType': 'UdtInstance'})
tagPaths = [str(tag['fullPath']) for tag in tags if not any(str(udt['fullPath']) in str(tag['fullPath']) for udt in udts)]
print len(tags)-len(tagPaths), 'tags removed that were part of UDT instances.'
else:
tagPaths = [str(tag['fullPath']) for tag in tags]
### filter the tag paths if required ###
#tagPaths = [path for path in tagPaths if 'Unit Parameters' in path]
print 'Number of tags: ', len(tagPaths)
allVals = [tagPaths]
for prop in readProps:
paths = ['{}.{}'.format(tag, prop) for tag in tagPaths]
vals = system.tag.readBlocking(paths)
vals = [val.value for val in vals]
allVals.append(vals)
csv = '"' + '","'.join(['tagPath'] + readProps) + '"\r\n'
csv += ''.join('"' + '","'.join(map(str, row)) + '"\r\n' for row in zip(*allVals))
### REQUIRES MY shared.util.clipboard LIBRARY
shared.util.clipboard.writeText(csv)
print 'Copied to clipboard.'