tag.get(propertyObject) not working

Hello all,
I have been attempting to pull specific properties out of tags that are returned by system.tag.browseConfiguration().
Following the post here I made the following script:

"""
This example will browse the root of the Tag Provider named "default".
For each tag found, prints the non-default properties.
"""
from com.inductiveautomation.ignition.common.sqltags.model import TagProp
# Specify the folder to browse. Modify this line to filter on a specific folder. 
folderPath = "CF1/CF1_BowlSpeed"
db = TagProp.HistoricalDeadband
histEnabled = TagProp.HistoryEnabled
# Start a non-recursive browse, and stores the configuration data in a variable
tagConfig = system.tag.browseConfiguration(folderPath, False)
# Iterate through the configuration data
for tag in tagConfig:
    #print "--------------------------------------------------------------------"
    propList = tag.getProperties()
    print "Property '%s' has a value of '%s'" % (str(db), tag.get(db))
    print "Property '%s' has a value of '%s'" % (str(histEnabled), tag.get(histEnabled))
    # Iterate through the list of properties
    for prop in propList:
        #Print the property name and value.
        if prop == db:
        	print "Property '%s' has a value of '%s'" % (prop, tag.get(prop))
        elif prop == histEnabled:
        	print "Property '%s' has a value of '%s'" % (prop, tag.get(prop))

The output is the following:

Property 'HistoricalDeadband' has a value of 'None'
Property 'HistoryEnabled' has a value of 'None'
Property 'HistoricalDeadband' has a value of '15.0'
Property 'HistoryEnabled' has a value of 'True'

My question is how is it that one method returns ‘None’ while the other method returns a value?
I would really like to pull the exact properties I want and not depend on the getProperties() method.
Thanks

Hmm. Good question :confused:

I think basically the Property objects you get from the TagProp enum don’t implement equality the way a Property should, so when you call get with it on the PropertySet (each TagConfiguration is a PropertySet) it doesn’t find it as a key. Seems like a bug on our side.

Try using properties from com.inductiveautomation.ignition.common.tags.config.TagConfigProps instead of the TagProp enum you’re using.

1 Like

That fixed it. Can you please give me a link to that in the API docs. I can only find com.inductiveautomation.ignition.common.sqltags.* and not the specific class you listed. I’m probably just not looking in the right place.

There’s no API docs to link you to, as far as I know…

It’s part of the same JAR file as the TagProp enum, so you should be able to find it by its class name if it has docs.

It does not unfortunately.
But it seems that all of the properties I have tried so far that are in the class TagProp have worked. Thanks for your help!

Turns out the members of the original TagProp enum each have .property() method you can call to get a usable Property as well.

Okay. I’m trying to pull out the historical scanclass for each tag configuration, but I get the following error:

Traceback (most recent call last):

  File "<event:mousePressed>", line 1, in <module>
  File "<custom-function updateTable>", line 44, in updateTable
TypeError: getOrDefault(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.config.Property

Ignition v7.9.5 (b2017111615)
Java: Oracle Corporation 1.8.0_151

Here is the relevant code:

	from com.inductiveautomation.ignition.common.sqltags.model import TagProp
	from com.inductiveautomation.ignition.common.tags.config import TagConfigProps
	from com.inductiveautomation.ignition.common.config import Property
	# Specify the folder to browse. Modify this line to filter on a specific folder. 
	propDict = {}
	propList = []
	folderPaths = ["aMemoryTags"]
	headers = ["Tag Path","Documentation","Data Type","Engineering Unit","History Enabled","Historical Deadband","Historical Scanclass","Engineering Low", "Engineering High"]
	db = TagConfigProps.HistoricalDeadband
	histSC = TagConfigProps.HistoricalScanclass
	histEnabled = TagConfigProps.HistoryEnabled
	engLow = TagConfigProps.EngLow
	engHigh = TagConfigProps.EngHigh
	engUnit = TagConfigProps.EngUnit
	dataType = TagConfigProps.DataType
	documentation = TagConfigProps.Documentation
	print Property.isInstance(TagProp)
	print Property.isInstance(TagConfigProps)
	# Start a non-recursive browse, and stores the configuration data in a variable
	for folderPath in folderPaths:
		tagConfig = system.tag.browseConfiguration(folderPath, False)
		# Iterate through the configuration data
		for tag in tagConfig:
		    #print "--------------------------------------------------------------------"
		    path = tag.getFullPath()
		    doc = tag.getOrDefault(documentation)
		    type = tag.getOrDefault(dataType)
		    unit = tag.getOrDefault(engUnit)
		    #print "Tag Path = '%s'" % (tag.getFullPath())
		    deadBand = tag.getOrDefault(db)
		    histSC = tag.getOrDefault(histSC)#histSC)
		    #print "Property '%s' has a value of '%s'" % (str(db), tag.getOrDefault(db))
		    hist = tag.getOrDefault(histEnabled)
		    #print "Property '%s' has a value of '%s'" % (str(histEnabled), tag.getOrDefault(histEnabled))
		    low = tag.getOrDefault(engLow)
		    #print "Property '%s' has a value of '%s'" % (str(engLow), tag.getOrDefault(engLow))
		    high = tag.getOrDefault(engHigh)
		    #print "Property '%s' has a value of '%s'" % (str(engHigh), tag.getOrDefault(engHigh))
		    if hist == True:
		    	propDict[path] = [doc,type,unit,hist,deadBand,histSC,low,high]
		    # Iterate through the list of propDict
		#print propDict.keys()
	    
	sortKeys = sorted(propDict)
	for key in sortKeys:
		#print key
		values = propDict.get(key)
		propList.append([key,values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7]])
	#for prop in propList:
	#	print prop
	ds = system.dataset.toDataSet(headers,propList)
	self.getComponent('Power Table').data = ds

The problem occurs on the line: histSC = tag.getOrDefault(histSC)#histSC)
My best guess is this is a bug, but I want to see if I am doing something wrong in referencing this property.

Thanks.

The property reference is fine, but after processing the first tag in the tagConfig you’re clobbering your histSC variable with something that isn’t a Property any more.

:sweat_smile: oops… Thanks Kevin.