Help needed for scripting OPC tag alarm configuration

Hello everyone,

I need your help to create a script that allows me to configure an alarm for an OPC tag and modify its properties. Specifically, the properties I need to be able to modify include:

  • Name
  • Priority
  • Display path
  • and other specific properties.

Currently, I managed to create a memory tag from scratch with this script:

# The provider and folder the Tag will be placed at. 
baseTagPath = "[default]MyFolder"
 
# Properties that will be configured on that Tag.
tagName = "myNewTag"
opcItemPath = "ns=1;s=[Simulator]_Meta:Sine/Sine0"
opcServer = "Ignition OPC-UA Server"
valueSource = "opc"
sampleMode = "TagGroup"
tagGroup = "Default"
 
# Configure the tag.
tag = {
            "name": tagName,           
            "opcItemPath" : opcItemPath,
            "opcServer": opcServer,
            "valueSource": valueSource,
            "sampleMode" : sampleMode,
            "tagGroup" : tagGroup
        }
 
# Set the collision policy to Abort. Thus, if a Tag already exists at the base path,
# we will not override the Tag. If you are overwriting an existing Tag, then set this to "o".
collisionPolicy = "a"
 
# Create the Tag.
system.tag.configure(baseTagPath, [tag], collisionPolicy)

My problem is that I need to modify an existing tag, not create one from scratch.

Could someone provide an example script or point me in the right direction to develop this? Any suggestions or resources would be greatly appreciated!

Thank you very much in advance!

1 Like

To modify an existing tag in Ignition, you can use the system.tag.editTag function.
Please check the user manual where you will find example scripts.

system.tag.editTag is deprecated in 8.1. Depends which version OP is using.

system.tag.configure is better suited.

See below:

@Artusito_FlashLight have a look at the collisionPolicy argument, and especially use the MergeOverwrite policy, or simple the Overwrite policy:

2 Likes

Thanks! Now using the system.tag.configure and this script I can configure the alarm settings of a tag, such as Name, Priority, Label... etc.

tagPath = "[default]MyTag"

currentConfig = system.tag.getConfiguration(tagPath, False)[0]

for alarm in currentConfig.get('alarms', []):
    if alarm['name'] == 'Alarm':  # Check the alarm name
        alarm['name'] = 'Test'  # Change the alarm name
        alarm['priority'] = 'High'  # Change alarm priority
        alarm['label'] = 'Description'  # Edit the alarm description
        break

results = system.tag.configure(tagPath.rsplit('/', 1)[0], [currentConfig], 'o')

Is there a way in your opinion to be able to use the script to automatically add the alarm to the tag without adding it manually?