How to derive the tag path from an alarm event

Given an alarm event object. Is there a way to obtain the tag path from that alarm. My alarm comes from a tag and I can get the 'source' property and this has the tag provider and the alarm name. I simply want the tag path for example '[default]My Tag' instead of 'prov:default/tag:My Tag/alarm:Test Alarm'

The source is a QualifiedPath object which has various structured mechanisms to extract data.

1 Like

toStringSimple, perhaps?

Probably the simplest that gives you the representation you're looking for:

from com.inductiveautomation.ignition.common import QualifiedPathUtils
tagPath = QualifiedPathUtils.toTagPathNew(alarmEvent.getSource()).toStringFull()
1 Like

Hi Paul, I just tried this:

from com.inductiveautomation.ignition.common import QualifiedPathUtils, QualifiedPath
tagpath = 'prov:default:/tag:Area A/Device 01/Level:/alm:High Alarm'
qp = QualifiedPath.parse(tagpath)
QualifiedPathUtils.toTagPathNew(qp).toStringFull()

and the result is:

u'[default]Area A/Device 01/Level'

But my expected result is:

u'[default]Area A/Device 01/Level/Alarms/High Alarm'

As this is the actual tagpath to that alarm, if you copy it from the tag browser
How would I produce that instead?

Also, is there any way to read/write the value of tags given a QualifiedPath object like above without converting to a string path?

Best I can do on short notice:

from com.inductiveautomation.ignition.common import QualifiedPathUtils, QualifiedPath, WellKnownPathTypes
from com.inductiveautomation.ignition.common.tags.config.properties import WellKnownTagProps

tagpath = 'prov:default:/tag:Area A/Device 01/Level:/alm:High Alarm'
qp = QualifiedPath.parse(tagpath)
tp = QualifiedPathUtils.toTagPathNew(qp)

alarm = qp.getPathComponent(WellKnownPathTypes.Alarm)
if alarm is not None:
	tp = tp.getChildPath("Alarms").getChildPath(alarm)

print tp.toStringFull()

The underlying APIs can accept TagPaths, but there's no (easy-ish) ways to access or consume them from scripting.

2 Likes

Ok cool, that works, cheers :slight_smile:

Minor correction to the import:
from com.inductiveautomation.ignition.common import WellKnownPathTypes