I am attempting to write a script that can programmatically change the parameters of a folder full of UDT instances. I am running into an issue where the system.tag.configure() call is failing silently. Can someone with better knowledge of the internals help me fix the script?
devicesBase = "[049_Production]test/Devices"
browseResults = system.tag.browse(
path=devicesBase,
filter={"tagType": "Folder"}
)
folders = [str(r["fullPath"]) for r in browseResults.getResults()]
print "Found", len(folders), "device subfolders"
totalUpdated = 0
for folderPath in folders:
# Get configs for THIS subfolder (recursive works here)
nodes = system.tag.getConfiguration(folderPath, True)
updated = 0
for item in nodes:
for key, value in item.iteritems():
if key != "tags":
continue
for udtConfig in value:
if str(udtConfig['tagType']) != 'UdtInstance':
continue
# -----------------------------
# PARAMETER UPDATE
# -----------------------------
if 'parameters' not in udtConfig:
continue
params = udtConfig['parameters']
if 'PLCDevice' not in params:
continue
# Read current value safely
if str(params['PLCDevice'].value) != 'Receiving':
continue
# parameter replacement
params['PLCDevice'] = {
'dataType': 'String',
'value': 'SPBG_049REC'
}
print "Updating PLCDevice for", udtConfig['name'], "to SPBG_049REC"
updated += 1
totalUpdated += 1
# Write once per folder if needed
if updated > 0:
system.tag.configure(folderPath, nodes, "m")
print "Updated", updated, "instances in", folderPath
print "TOTAL PLCDevice updates:", totalUpdated
What is the error you get from the console/gateway logs?
add more print statements to the log and watch its progress. Like David mentioned, are there any errors in the gateway logs?
Agreed. Add more print statements. Are you SURE it's getting into the if updated > 0: condition?
Avoid print. Use a logger. In gateway scope, print doesn't go to the logs visible from the gateway Web UI, but only to the wrapper log text file.
1 Like
Plus you can name your logger, do different levels like info/error/debug, and filter on both of these items.
2 Likes
You're not checking its return either. I'd start with that.
I found the solution. I wasn’t setting the udtConfig['parameters'] = params after changing the internals of the dictionary. The examples from the website and help from a coworker got me the answer. On a sidenote to this, does system.tag.getConfiguration() get a revamp in Ignition 8.3?
--------------------------------------
CONFIG
--------------------------------------
devicesBase = "[049_Production]test/Devices"
--------------------------------------
BROWSE DEVICE SUBFOLDERS (ONCE)
--------------------------------------
browseResults = system.tag.browse(
path=devicesBase,
filter={"tagType": "Folder"}
)
folders = [str(r["fullPath"]) for r in browseResults.getResults()]
print "Found", len(folders), "device subfolders"
--------------------------------------
PROCESS EACH SUBFOLDER
--------------------------------------
totalUpdated = 0
for folderPath in folders:
# Get configs for THIS subfolder (recursive works here)
nodes = system.tag.getConfiguration(folderPath, True)
updated = 0
# IA-style traversal
for item in nodes:
for key, value in item.iteritems():
if key != "tags":
continue
for udtConfig in value:
if str(udtConfig['tagType']) != 'UdtInstance':
continue
# -----------------------------
# PARAMETER UPDATE
# -----------------------------
if 'parameters' not in udtConfig:
continue
params = udtConfig['parameters']
if 'PLCDevice' not in params:
continue
# Read current value safely
if str(params['PLCDevice'].value) != 'CIP':
continue
# 🔑 CORRECT parameter replacement
DeviceID = str(params['DeviceID'].value)
params = {
"DeviceID": {
"dataType": "String",
"value": DeviceID
},
"PLCDevice": {
"dataType": "String",
"value": 'SPBG_049CIP'
}
}
udtConfig['parameters'] = params
updated += 1
totalUpdated += 1
# Write once per folder if needed
if updated > 0:
system.tag.configure(devicesBase, nodes, "m") # ✅ FIXED
print "Updated", updated, "instances in", folderPath
print "TOTAL PLCDevice updates:", totalUpdated