# This script generates a data set for a single PLC Shift app.
# Call this script with the name of the app. The app name
# is used to find the rights tags for just this app. This
# script should be called periodically to update the view
def GetData(appName):
headers = ["Tag Name", "Value", "Units", "Documentation"]
# https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-browse
# Get all atomic children of this path. Note that the tag are in the 'default' group
# and that we create a path by prepending the top level group name 'PlcShift'
results = system.tag.browse(path = "[default]PlcShift/" + appName, filter = {'tagType':'AtomicTag'})
# Declare varibles to hold the results that we need to create the data set
paths = []
names = []
units = []
docs = []
for i in results:
#iterate over the results and extract the information that
# we need. i is each record in the list
#extract the path aka full name for each tag in the results set
paths.append(str(i['fullPath']))
# extract the display name for each tag in the results set
names.append(i['name'])
# get the config for this tag using its full name
config = system.tag.getConfiguration(str(i['fullPath']))
# extract the units for this tag. The config is returned
# as a list, so we need to look at the first (and only)
# record in the list, which is why we have '[0]'
unit = config[0]['engUnit']
units.append(unit)
# get the documentation
doc = config[0]['documentation']
docs.append(doc)
#https://forum.inductiveautomation.com/t/best-way-to-read-multiple-tags-and-bind-them-to-a-table/55023
# get all tag values using the collection of paths
values = system.tag.readBlocking(paths)
# commented out debug code. You can see the results of print
# statements in the console
#print results
#print results
#print paths
#print headers
#print values
#declare a collection to hold the data
data = []
for i in range(len(values)):
# use the size of the values collection as an iterator
# for each value, add the static information
# about the tag
data.append([names[i], values[i], units[i], docs[i]])
#print data
# create a data set from the collection
dataset = system.dataset.toDataSet(headers, data)
return dataset