I am trying to save a file to the gateway with the following script,
filename = system.file.saveFile(str(time) + "_" + str(sn) + ".txt")
if filename is not None:
system.file.writeFile(filename,text)
but this gives the error
Error running action 'dom.onClick' on Straightening@D/root/checkButton: Traceback (most recent call last): File "<function:runAction>", line 13, in runAction File "<module:CheckPart>", line 78, in savePart AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'saveFile'
What should I be doing instead to save a file to the gateway via a script?
You are trying to use a Vision function in Perspective. Vision has direct access to the filesystem at the client machine, and can therefore present a file/folder chooser and can write results directly to that filesystem.
Perspective runs all scripts in the gateway, and the Vision file chooser doesn't exist for it. If you really want to save in the gateway, you will need to already know what folder and filename to use.
If you want to save in the client, you need to use system.perspective.download()
to prompt the user to save the file. You won't have any say in where the user puts it in their system, though you can (and should) suggest a file name.
In other words - system.file.writeFile
is the correct function to use to write the file to the gateway, but you need some other mechanism to get the 'path to save the file to', such as a simple text field or popup view or something else; system.file.saveFile
is a poorly named, poorly-located Vision only function.
4 Likes
I see I just have to give it the correct path and it worked. The documentation that said this worked in Perspective was where I got the script example from so I figured everything in the script would work with Perspective.
Can you link whatever documentation page you got that example from?
https://docs.inductiveautomation.com/display/DOC81/system.file.writeFile
Scope has both vision and perspective in it which seems to be true for the topic of the page, writeFile, but I assumed it also meant the same for the whole snippet.
2 Likes
Documentation already updated. This right here is why you guys are really the best around.
2 Likes