Importing the CSV file in Ignition Perspective

How to import or read the CSV file in Ignition Perspective.
I am using the below code for CSV file but I am getting the error as "AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'openFile' "
Is there any way for it?

    import csv
path = system.file.openFile("csv")
csvData = csv.reader(open(path))
header = csvData.next()
dataset = system.dataset.toDataSet(header ,list(csvData))
event.source.parent.getComponent('Table').data = dataset

I'm using the following code to open a CSV and execute a script to add tags

import csv	#import the python csv library
# Script tools to open csv file and import tags of specified UDT Type

# Open csv file through file selector
def openFile():
	filePath = system.file.openFile("csv","%user%")
	csvFile = open(filePath, 'r')
	reader = csv.DictReader(csvFile, delimiter = ';')
	line_count = 0
	print reader.fieldnames
	for row in reader:
		#print row
		addTag( row )

From a Perspective session, this should be closer to what you're looking for.

1 Like

Hi Frederic_Avet,
I have used your script which you provided above but I am not able to browse the CSV file, it is not giving any error also.

Remember that, Perspective doesn't have direct access to the client machines file system. You will need to use the file upload component to get the file.

In the post that @JordanCClark linked to, the OP was using the script in the onFileRecieved event of this component.

1 Like