Python AttributeError when included in dir()

This is probably a lack of my Java knowledge…

I got this from someone at IA to get a full list of all of the default alarm props:

I’m trying to do something similar but for tags in general (history would be good as well).
I searched the API and found com.inductiveautomation.ignition.common.tags.config.BasicTagConfiguration and com.inductiveautomation.ignition.common.tags.config.BasicTagConfigurationModel which seemed to be what I was after maybe… and proceeded to try to use the getValues method, but got an AttributeError for both:

Can someone explain this, and point me in the right direction?
@PGriffith? :slight_smile:

You are trying to use an instance property (really translated from NetBeans getter .getValues()) on a class. You need to use it on an instance.

How does what i’m doing differ from the alarm code though?

com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties, AlarmModeProperties
properties = {}
properties.update(dict((s.getName(), s.getDefaultValue()) for s in CommonAlarmProperties.values()))

Edit:
Using this works, but it turns out I don’t think I have the right objects to get the default config :confused: any ideas?

from com.inductiveautomation.ignition.common.tags.config import BasicTagConfigurationModel
from com.inductiveautomation.ignition.common.tags.config.types import TagObjectType
from com.inductiveautomation.ignition.common.tags.paths import BasicTagPath

tagPath = BasicTagPath('path')
a = BasicTagConfigurationModel(tagPath,   # path
							   True,      # mutable
							   False,     # inherited
							   True,      # isNew
							   TagObjectType.AtomicTag) # type
print a.values

Edit:
a.values just prints an empty list

CommonAlarmProperties is an enum class, which naturally has a values() method (on the class). Distinct from a getValues() method of BasicTagConfigurationModel which is not an enum. Your constructor looks fine. I don’t know why it doesn’t work. (But I haven’t explored in this area. You can keep blazing a trail…)

You’re not doing anything wrong (necessarily), it’s just that BasicTagConfigurationModel doesn’t do what you expect it to do.

It looks like, at a glance, it’s still ‘just’ an extension of the PropertySet model that everything else tag related uses - TagConfigurationModel and its related members are extended to allow, for instance, ‘layering’ of snapshots over each other, but you still need to derive those snapshots from somewhere. Ultimately, the more helpful thing for what you’re trying to do is probably going to be using com.inductiveautomation.ignition.common.tags.config.BasicTagConfiguration#createEdit(com.inductiveautomation.ignition.common.tags.model.TagPath), then extracting each property (or its default) using com.inductiveautomation.ignition.common.config.PropertyValueSource#getOrDefault.

To get a static reference to the properties you care about, refer to the aptly-named com.inductiveautomation.ignition.common.tags.config.properties.WellKnownTagProps.

2 Likes

Thanks Paul, that’s gotten me somewhere.
Onto the next dumb question :slight_smile:
How would I get a list of all of the fields of WellKnownTagProps? I can use dir() but that will return methods and everything else as well. Is there something else I can use?

Also, I actually don’t think I need to use BasicTagConfiguration* or PropertyValueSource at all as the WellKnownTagProps has a method getDefaultValue().

Java’s reflection API, though I haven’t done a lot with it from Jython. E.G, something like this from the class definition, translated to Jython:

There’s no central registry or anything; as of 8.0 a key aspect of the tag configuration model is that any tag can have any number of properties, and the ‘actors’ that actually do anything with the tag configuration simply ‘ask’ for what they care about.

4 Likes