Good Morning, I’m writing a script for my OEE monitoring system to monitor the number of active and down machines for all the machines in the shop. I’m using a tag change script that executes when the boolean value of selected tags changes. The original script is below:
########################################################################
# Specify the paths.
paths = [
"[default]Machines/Machine_Information_Template/Machine_Activity/Down",
"[default]Machines/MT_Robot/Machine_Activity/Down"
#^add your tag path for a new machine above
]
active = 0
down = 0
# Read tags
values = system.tag.readBlocking(paths)
# Loop through results
for i in range(len(values)):
tagValue = values[i].value
if tagValue == False:
active += 1
else:
down += 1
print active
print down
system.tag.writeBlocking("[default]Main_Metrics/Overall/Active_Machines", active)
system.tag.writeBlocking("[default]Main_Metrics/Overall/Down_Machines", down)
########################################################################
In the first iteration, everything was working fine. I updated the code so that the paths in my machine folder associated with the "down" tag is generated automatically, eliminating the need to hardcode the tag paths for each machine.
The code still runs as expected in the Script Console, but not when triggered by the tag change event.
Here is the updated version of the code:
########################################################################
# Find all tags named "Down" under machine folder
def findTagsNamedDown(path):
found = []
results = system.tag.browse(path)
for r in results.getResults():
name = r["name"]
fullPath = r["fullPath"]
hasChildren = r["hasChildren"]
if name == "Down":
#Store string path
found.append(str(fullPath))
if hasChildren:
found.extend(findTagsNamedDown(fullPath))
return found
baseFolder = "[default]Machines"
#Find all Down tags
paths = findTagsNamedDown(baseFolder)
#Make sure every entry is a string
paths = [str(p) for p in paths]
#Count active vs down
active = 0
down = 0
values = system.tag.readBlocking(paths)
for v in values:
tagValue = v.value
if tagValue == False:
active += 1
else:
down += 1
print active
print down
# Write machine status values to active and down machines tags
system.tag.writeBlocking("[default]Main_Metrics/Overall/Active_Machines", active)
system.tag.writeBlocking("[default]Main_Metrics/Overall/Down_Machines", down)
########################################################################
Any guidance would be greatly appreciated. I've also attached screenshots of the gateway event script configuration and script console. Thank you!

