System.file.writeFile issue with Perspective

This is probably a documentation issue.

When I try to use the code snippet from the documentation (in Perspective) it tells me that saveFile isn’t an attribute of system.file. If I use the ctrl+space suggestions of system.file from a button’s onClick event in Perspective there is no saveFile method. The code examples show using saveFile to create the file and then system.file.writeFile to write to the file.

It’s been a few years since I wrote to a file from Ignition so I don’t remember how it’s supposed to work.

Ultimately, I’m just trying to export data from historical tag data to a .csv. I’m starting with the “easy stuff” so I’m just trying to write a text string to a file.

saveFile doesn’t actually save a file. It opens a file chooser dialog looking at the local filesystem to allow the user to construct a file path+name. That string is the return value. It only works in Vision because browsers don’t permit this kind of action.

writeFile is then used to actually perform the save operation. Again, it only works (locally) in Vision because browsers don’t permit this kind of action. The alternative in Perspective is to construct a downloadable file first, then place a link to it in your view. Following that link uses the browser’s download mechanism, which may or may not automatically offer a dialog to select a location and name to save under.

Perspective is fundamentally different from Vision. This is one of those differences.

1 Like

To add onto @pturmel’s response, please look at the available scopes for the functions you’re attempting to use; saveFile() is only available in Vision Client scripting - not Perspective Sessions.

The writeFile() function IS available in Perspective, but ALL functions in Perspective run on the Gateway (so that’s where the file is written to), so you will never see a file on your local machine as a result of using writeFile().

There’s no mechanism in Perspective as of today that allows for exporting or downloading files of any type - short of coupling with the WebDev Module.

1 Like

Thanks for the clarification. I vaguely remember that from training now that you mention it.

@cmallonee I saw your other response on this about the file being saved on the server. It threw me a bit when I tried to use the example from the help and it blew up. The scope makes sense.

I was having trouble getting it to accept my path. I had to escape “” in my path. It’s been a while since I did this and after figure out the problem it was kinda obvious. It’s not every year I have to write to a file from an HMI.

Thanks for your help.

1 Like

I figured out a pretty good solution for what I need to do. The customer wants to be able to select data points and have them displayed in a grid. Then they want to be able to hit a button to download a CSV file of the data from the grid.

This code got it done:
dataset = self.getSibling(“Table”)
export = system.dataset.toCSV(dataset, 1, 0, 0)“test.csv”, data=export) isn’t documented on the official documentation yet. I found it on the intellisence thing and poked it until it worked.

Of course, selecting data points to display on the grid is the next fun challenge. I suspect this code will export all datapoints in the dataset whether I have them hidden or not.


It’s not documented because no one here knows about it (the dev who placed it is out right now). I’ll request it be added to the documentation.

1 Like

Thanks. This was a dumb luck situation.

I appreciate your help as always. I have been developing better stuff in general thanks to your help. I’m still using some of the stuff you showed me to muddle my way through unrelated things. My general approach to developing Perspective projects has improved thanks to your feedback.

I also appreciate the feature. It is EXACTLY what I needed. So thumbs up to that developer also :slight_smile:

1 Like

Is this an official way to save a table to CSV on the local machine ? is an official option. It just didn’t seem to be communicated to everyone when it rolled out.

Documentation can be found below.

1 Like

That’s what I thought, but when i tried the code posted above on a table in my program it doesn’t work. So wasn’t sure if that was an official method.

I put the following code in a button script referencing a table.

dataset = self.getSibling(“Table”)
export = system.dataset.toCSV(dataset, 1, 0, 0)“test.csv”, data=export)

The error in the gateway log shows…

org.python.core.PySyntaxError: SyntaxError: (u"no viable alternative at character '\u201c'", ('', 4, 38, u'\\u201ctest.csv\u201d, data=export)\n'))

at org.python.core.ParserFacade.fixParseError(

at org.python.core.ParserFacade.parse(

at org.python.core.Py.compile_flags(

at com.inductiveautomation.ignition.common.script.ScriptManager.compileFunction(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.compileFunctionSuper(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.getOrCreateDelegate(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.(

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.compileFunction(

at com.inductiveautomation.ignition.common.script.ScriptManager.compileFunction(

at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(

at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(

at com.inductiveautomation.perspective.gateway.action.ActionDecorator.runAction(

at com.inductiveautomation.perspective.gateway.action.SecuredAction.runAction(

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(

at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$

at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$

at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$

at java.base/java.util.concurrent.Executors$ Source)

at java.base/ Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$ Source)

at java.base/ Source)

That’s a pure syntax error, not a problem with the logic. I can’t tell from your code block precisely what the problem is, but it isn’t a problem with Possibly it is the paired quotation marks. You must use the straight quote marks in code.


Or the fact that the variable dataset is a list, whereas the function call expects a Dataset.

1 Like

I’m using Ignition version 8.1.4 and this method doesn’t seem to work anymore?

I put the following code in a button script referencing a table, similar to a post above:

dataset = self.getSibling("Table")
csv = system.dataset.toCSV(dataset, showHeaders = True, forExport = False)“test.csv”, data=csv)

But on button press I get the following error:

Unable to run action 'component.onActionPerformed' on Main Views/TagHistory@D/root/Button: code could not be compiled.

That error generally means a syntax error. I see curly quotes in your code’s third line around test.csv. Those should be ASCII straight double quotes. This commonly occurs when someone posts code without proper formatting marks, and this forum tries to “prettify” the “paragraphs”, like here. Don’t cut and paste from improperly formatted code on forums.


You’re completely right. Thank you.