I am trying to use the script shown on the Ignition user manual for exporting tag history to a CSV, but I am missing something. The version is slightly older being 8.0.1.7, so I am not sure if that is what is making the difference or if there is some other configuration that is happening. On the project on my computer, it works perfectly fine (I am using 8.1.43), but when I try to use it on the customers computer it comes up with the following error:
Traceback (most recent call last):
File "<input>", line 20, in <module>
File "<input>", line 7, in browse
TypeError: 'NoneType' object is not iterable
Here is the script that is being ran, I have tried including the gateway in the path but that did not change anything. I am able to see data on trends, so I know there is data there. Any help with this would be greatly appreciated, thank you!
# Our browse function that will browse for historical tags.
# By setting this up as a function, it allows us to recursively call it to dig down through the specified folder.
# Pass in an empty list that we can add historical paths to, and the path to the top level folder.
def browse(t, path):
# Loop through the results of the historical tag browse, and append the path to the empty list.
for result in system.tag.browseHistoricalTags(path).getResults():
t.append(result.getPath())
# If the result is a folder, run it through the browse function as well.
# This will continue until we are as deep as possible.
if result.hasChildren():
browse(t, result.getPath())
# Start with an empty list to store our historical paths in.
historyPaths = []
# Call the browse function, passing in an empty list, and the folder that we want to browse for historical tags.
# This path is a placeholder. It should be replace with your valid path.
browse(historyPaths, path='histprov:Hixton_SQLServer:/drv:default:/tag:GreenhouseIII')
# Create another empty list to store our tag paths that we will pull out of the historical paths.
tagPaths = []
# Loop through the list of historical tag paths, split out just the tag path part,
# and push it into our tag path list.
for tag in historyPaths:
tagPaths.append("[default]" + str(tag).split("tag:")[1])
# Now that we have a list of tag paths, we need to grab the historical data from them.
# Start by creating a start and end time.
endTime = system.date.now()
startTime = system.date.addDays(endTime, -5)
# Then we can make our query to tag history, specifying the various parameters.
# The parameters listed for this function can be altered to fit your need.
data = system.tag.queryTagHistory(paths=tagPaths, startDate=startTime, endDate=endTime, returnSize=10, aggregationMode="Average", returnFormat='Wide')
# Turn that history data into a CSV.
csv = system.dataset.toCSV(data)
# Export that CSV to a specific file path. The r forces it to use the raw path with backslashes.
system.file.writeFile(r"C:\myExports\myExport.csv", csv)
Blockquote