Tag.datatype - How to compare the dataType property of the Tag

I am trying to write the blank values to the Tag depending on the type of Tag. For example, ’ ’ if String, 0 if Int, etc…
I am using browseTags to get the tag datatype as below -

Here, the question is how do I compare the datatype of the Tag in If condition as tag.dataType == 'String': does not work.

Thanks !



That said, browse tags is considered deprecated in v8. Consider using system.tag.browse.
Also, a use of dictionaries and lists can help keep things orderly.

typeDict = {
			'Boolean': False, 

tagSkipList = [

tagPath = '[LabTesting]MV-Lillebonne1/Specs'

tagBrowse = system.tag.browse(tagPath)

tagOutputList = []
values = []

for tag in tagBrowse.getResults():
	if tag['name'] not in tagSkipList:
		# Add full path to tha tag list
		if str(tag['dataType']) in typeDict.keys():
print tagOutputList
print values
system.tag.writeBlocking(tagOutputList, values)
1 Like

system.tag.browseTags was the way to get information on tags in Ignition 7.9 and below. In Ignition 8.0+, system.tag.browse is a better option. That in combination with system.tag.getConfiguration will get you what you need

tagPath = '[default]MyFolder'
tags = system.tag.browse(tagPath).getResults()
for tag in tags:
	dataType = system.tag.getConfiguration(tag['fullPath'])[0]['dataType']
1 Like

Wow this is great ! Wonder how long does it takes to adopt this mindset where you can automatically convert any piece of code into the most effective and easily readable language.

I wish I could take full credit. I’m somewhat of a visual learner, so as I see other’s examples where it makes sense for readability, I’ll try to adopt it. The rest is long hours of tinkering. :wink:

1 Like

I am using Ignition 8.0.13

I am trying to get the DATATYPE of a memory tag that is an Integer
using scripting.

So I searched this forum and found this post.
So I tried to just use the script console
using the script from JordanCClark

However when I execute the script I get an error:
KeyError: ‘dataType’
on the line of script: if str(tag[‘dataType’]) in typeDict.keys():

I tried to print type(tags)
and it listed a bunch of properties of the tag, but not ‘dataType’.
Nothing that it listed showed anythning like INTEGER.


Please show us the result of: print tags

Actually, I think I know what happened. One moment while I get properly attired.


You did the browse on a single tag. This won’t work because browse() will get all the children, but the dataType is on the top level.

This should return the browse of a single tag:

def browseSingle(tagName):
	# Get the parent path of the tag
	tagPath = tagName[:tagName.rfind('/')]
	# Browse the parent path
	tags = system.tag.browse(tagPath).getResults()
	# Return the browse result of the tag.
	# If it doesn't exist, return -1
	for tag in system.tag.browse(tagPath).getResults():
		if str(tag['fullPath']) == tagName:
			return tag
	return -1

tagName = '[default]Test/IntMemoryTag'

tag = browseSingle(tagName)

if tag != -1:
	print tag['fullPath'], '--', tag['dataType']
1 Like

ahhh, got it.