Perspective PowerChart Advanced CSV Export Utility

Hi, i used the "Perspective PowerChart Advanced CSV Export Utility" available on "Ignition Exchange | Inductive Automation". When i try to export powerchart data to a csv file it creates a file with only the date and time stamps of the points, but no actual data from that time stamp. This is the script that is used:
Why is there no data saved with the timestamps?

def runAction(self, event):
	tagPaths = []
	aggregateModes = []
	histPaths = []
	self.view.custom.Saving = True
	array = self.view.params.Pens
	for row in array:
		rowObj = row['data']
		if rowObj['aggregateMode'] == "default":
			aggregateModes.append(self.view.params.DefaultAggregationMode)
		else:
			aggregateModes.append(rowObj['aggregateMode'])
		histPaths.append(rowObj['source'])
	for histPath in histPaths:
		#histpath = ("4051_HBY/" + str(histPaths).split("tag:")[1])
		tagPaths.append("4051_HBY/" + str(histPaths).split("tag:")[1])
		tagPaths.append(histpath)
	points = self.view.custom.Points
	endTime = self.view.params.EndDate
	startTime = self.view.params.StartDate
	
	#data = system.tag.queryTagHistory(paths=["4051_HBY/pro/20_production/v100_chipsline/01_operational/linestatus"],startDate=startTime, endDate=endTime, returnSize=points, returnFormat='Wide', aggregationMode = aggregateModes)
	dataSet = system.tag.queryTagHistory(paths=['4051_HBY/pro/20_production/v100_chipsline/01_operational/linestatus'], startDate=startTime, endDate=endTime, returnSize=8, aggregationMode="Average", returnFormat='Wide')	
	csv = system.dataset.toCSV(dataSet)
		
	# Use system.file.saveFile to have the user find a directory to write to.
	filePath = system.perspective.download("TrendExport.csv", csv, "Comma Separated Values")
		
	self.view.custom.Saving = False

Hi Zino,
The way you have modified the script, the only working lines are the last 6 lines of the script, the others will have no impact on the CSV file. This is a good way to test it, you could possibly even copy these lines into your script console and test them there.
My first suggestion is to ensure you have the correct tag path - to get the tag path, you need to right-click on the tag in your tag browser and select 'copy path' then paste it over the tag path you have. I know that whenever I use this tool, I have the tag provider in square brackets before the tag path e.g. '[default]4051_HBY/pro/...'.
I also notice you are using a mixture of single and double quotes, I know my script doesn't provide the best example of this, but it may help to make these all the same, either is good, just pick one and stick with it.
If you set the returnSize to -1 it will return all the data points recorded for that tag, this will help you see if there is any data recorded over the interval you have selected or if Ignition is returning calculated points.
Aggregation Mode and ReturnFormat are optional parameters, you can delete these to simplify your testing.

Looking at your code, you've done a fair bit of hacking to try to get it to work, once you've found the issue, and you want to restore the original code, here it is:

	import json
	
	tagPaths = []
	aggregateModes = []
	histPaths = []
	self.view.custom.Saving = True
	array = self.view.params.Pens
	for row in array:
		rowObj = row['data']
		if rowObj['aggregateMode'] == "default":
			aggregateModes.append(self.view.params.DefaultAggregationMode)
		else:
			aggregateModes.append(rowObj['aggregateMode'])
		histPaths.append(rowObj['source'])
	for histPath in histPaths:
		tagPaths.append("[default]" + str(histPath).split("tag:")[1])
	points = self.view.custom.Points
	endTime = self.view.params.EndDate
	startTime = self.view.params.StartDate
	
	data = system.tag.queryTagHistory(paths=tagPaths,startDate=startTime, endDate=endTime, returnSize=points, returnFormat='Wide', aggregationModes = aggregateModes)
	
	csv = system.dataset.toCSV(data)
	
	# Use system.file.saveFile to have the user find a directory to write to.
	filePath = system.perspective.download("TrendExport.csv", csv, "Comma Separated Values")
	
	self.view.custom.Saving = False

EDIT:
For reference, the ignition docs for the queryTagHistory function can be found here: https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory

1 Like

Hi Tom,
Thanks for your answer, i somehow managed to get it working. Thank you for your respons. I use the tag folder [4051_HBY] instead of [Default] i think that is the only change i needed o make to get it working.
Here is the final code:

def runAction(self, event):
		import json
		
		tagPaths = []
		aggregateModes = []
		histPaths = []
		self.view.custom.Saving = True
		array = self.view.params.Pens
		for row in array:
			rowObj = row['data']
			if rowObj['aggregateMode'] == "default":
				aggregateModes.append(self.view.params.DefaultAggregationMode)
			else:
				aggregateModes.append(rowObj['aggregateMode'])
			histPaths.append(rowObj['source'])
		for histPath in histPaths:
			tagPaths.append("[4051_HBY]" + str(histPath).split("tag:")[1])
		points = self.view.custom.Points
		endTime = self.view.params.EndDate
		startTime = self.view.params.StartDate
		
		data = system.tag.queryTagHistory(paths=tagPaths,startDate=startTime, endDate=endTime, returnSize=points, returnFormat='Wide', aggregationModes = aggregateModes)
		
		csv = system.dataset.toCSV(data)
		
		# Use system.file.saveFile to have the user find a directory to write to.
		filePath = system.perspective.download("TrendExport.csv", csv, "Comma Separated Values")
		
		self.view.custom.Saving = False
1 Like

Hi Tom,
I am relatively new to Ignition so please forgive my ignorance.
I don't know how to add a post to this topic without specifically replying to posts already there which is not my aim.
I am tyring to get the above component to work. What I am not sure of is how to assign tags to be exported. Must they be predifined in Designer view or can the end user of this page nominate which tags to export data on?
Either way I can't see how to specify the tags. Any help would be appreciated please.

Hi Andrew,
I don't work with designer but this is how i did it in perspective:
First of all the tag you want to export should have History enabled in a specific database.
Then you need to add this tag that u want to export in the powerchart. Only the "pens" in your powerchart will be exported.
Hope this will help.

Hi Zino,
Thanks for the reply. I sort of get what you are saying. Sorry but I am new to Ignition.
Yes I have history enabled for my tags, did that when first setting them up.
I have an ad hoc powerchart for my client to pick and choose what tags they want to trend. See image. Is the TrendDataExportPopup meant to be a part of this page? At the moment I have created a separte page where this popup is sitting and it looks like the second image attached.
Can you please descibe a bit more what goes where?


Hi Andrew,
Looks like you aren't quite using the resource right.
I would suggest importing the entire project into your gateway and using the "export...send to project" feature to incorporate them into your project.
I see that you have managed to import the TrendDataExportPopup view into your project however you appear to be trying to use it as a page - this won't work unless you make significant changes to the code.
You need to import the Trend view into your project as well, looking at the Trend view, you will see a small cloud icon at the top right hand side which has an onClick event that opens up the popup and links the data required to assign the tags to be exported.

The way the script is written, the popup should be called from the same view as the trend.