# How can I use SaveData to write an ASCII file in ParaView 3.98.1?

**URL:** https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303
**Category:** ParaView Support
**Tags:** vtk
**Created:** [September 9, 2020, 1:02pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303 "2020-09-09T13:02:05Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 1:02pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/1 "2020-09-09T13:02:05Z")

</div>

Hello,

I am writing an automation script for an old project and I need some help with `pvpython` from [Paraview 3.98.1](https://www.paraview.org/download/). The function `SaveData()` in this version does not exist. I found its implementation [here](https://kitware.github.io/paraview-docs/latest/python/_modules/paraview/simple.html) and moved it to my code. How can I save a file as ASCII? Calling it like `SaveData(filename, proxy=px, FileType='Ascii')` saves my files as binaries (awkward behavior).

Kind Regards,  
Anna

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 1:16pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/2 "2020-09-09T13:16:08Z")

</div>

3.98.1 is very very old.

Any reason not to update ?

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 1:37pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/3 "2020-09-09T13:37:15Z")

</div>

I need this version because some of my codes in the scripting pipeline handle very specific `vtk` files. Using the `SaveData()` function of the latest versions ended up creating different metadata in my final files, and when I process them it ends up destroying my results. It is easier at the moment to use an older version of Paraview than to modify all my codes.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 1:39pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/4 "2020-09-09T13:39:44Z")

</div>

Then just create a writer manually of the right format you want.

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 1:47pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/5 "2020-09-09T13:47:51Z")

</div>

That is exactly what I do not want.

I would like to understand how `SaveData()` from version 3.98.1 works. When I save a `vtk` through Paraview’s graphical interface the file ends up being exactly the way I need it. I tried to use the trace of this version: it shows everything I do, except the part of saving the final file!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 1:48pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/6 "2020-09-09T13:48:54Z")

</div>

Because SaveData is not implemented in Python in ParaView 3.98.1

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 1:57pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/7 "2020-09-09T13:57:01Z")

</div>

I found its implementation [here](https://kitware.github.io/paraview-docs/latest/python/_modules/paraview/simple.html) and moved it to my code. The website is not working now, but it was yesterday. Maybe it is an internal problem? Anyway, the code is attached at the end of this reply.

It works and saves my files, but not as ASCII.

```
# -----------------------------------------------------------------------------

def SetProperties(proxy=None, **params):
	"""Sets one or more properties of the given pipeline object. If an argument
	is not provided, the active source is used. Pass a list of property_name=value
	pairs to this function to set property values. For example:
		SetProperties(Center=[1, 2, 3], Radius=3.5)
	"""
	if not proxy:
		proxy = active_objects.source
	properties = proxy.ListProperties()
	for param in params.keys():
		pyproxy = servermanager._getPyProxy(proxy)
		pyproxy. __setattr__ (param, params[param])

# -----------------------------------------------------------------------------

def CreateWriter(filename, proxy=None, **extraArgs):
	"""Creates a writer that can write the data produced by the source proxy in
		the given file format (identified by the extension). If no source is
		provided, then the active source is used. This doesn't actually write the
		data, it simply creates the writer and returns it."""
	if not filename:
		raise RuntimeError ("filename must be specified")
	session = servermanager.ActiveConnection.Session
	writer_factory = servermanager.vtkSMProxyManager.GetProxyManager().GetWriterFactory()
	if writer_factory.GetNumberOfRegisteredPrototypes() == 0:
		writer_factory.UpdateAvailableWriters()
	if not proxy:
		proxy = GetActiveSource()
	if not proxy:
		raise RuntimeError ("Could not locate source to write")
	writer_proxy = writer_factory.CreateWriter(filename, proxy.SMProxy, proxy.Port)
	writer_proxy.UnRegister(None)
	pyproxy = servermanager._getPyProxy(writer_proxy)
	if pyproxy and extraArgs:
		SetProperties(pyproxy, **extraArgs)
	return pyproxy

# -----------------------------------------------------------------------------

def SaveData(filename, proxy=None, **extraArgs):
	"""Save data produced by 'proxy' in a file. If no proxy is specified the
	active source is used. Properties to configure the writer can be passed in
	as keyword arguments. Example usage:
		SaveData("sample.pvtp", source0)
		SaveData("sample.csv", FieldAssociation="Points")
	"""
	writer = CreateWriter(filename, proxy, **extraArgs)
	if not writer:
		raise RuntimeError ("Could not create writer for specified file or data type")
	writer.UpdateVTKObjects()
	writer.UpdatePipeline()
	del writer
	
# -----------------------------------------------------------------------------
```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 2:00pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/8 "2020-09-09T14:00:48Z")

</div>

Does this work ?

```
SaveData(filename, proxy=px, DataMode='Ascii')
```

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 2:04pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/9 "2020-09-09T14:04:02Z")

</div>

The generated files are still binary. ☹

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 2:06pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/10 "2020-09-09T14:06:04Z")

</div>

You’ll have to dig into the C++ code and run in debug mode to understand what is going on. Not a trivial task though.

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 2:49pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/11 "2020-09-09T14:49:19Z")

</div>

I [found out](https://paraview.paraview.narkive.com/xP9MEvao/vtk-ascii-to-binary) I can also do the following to save my file as ASCII in this version:

```
write = servermanager.writers.DataSetWriter()
write.Input = vtk_file
write.FileName = filename
write.FileType = 'Ascii'
write.UpdatePipeline()

```

I do not know, however, how to link a `proxy` (see `SaveData`'s call) using this approach since the class does not have a `Proxy` attribute.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 9, 2020, 2:51pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/12 "2020-09-09T14:51:29Z")

</div>

Right, DataMode is for XML writers.

The link in question should be automatic (thanks to the SetProperties call) and your initial code seems correct.

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 2:55pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/13 "2020-09-09T14:55:45Z")

</div>

I edited the `SaveData()` implementation post because I forgot to show the main function.

---

<div class="post-metadata">

### Author: ![acmresende](https://discourse.paraview.org/user_avatar/discourse.paraview.org/acmresende/32/4862_2.png) [@acmresende](https://discourse.paraview.org/u/acmresende)
#### Post date: [September 9, 2020, 8:05pm UTC](https://discourse.paraview.org/t/how-can-i-use-savedata-to-write-an-ascii-file-in-paraview-3-98-1/5303/14 "2020-09-09T20:05:43Z")

</div>

Well, I used `SaveData()` to save a binary file with the `proxy` I need and then used `DataSetWriter()` to change my `FileType` to ASCII. It is not a beautiful solution since `SaveData()` is supposed to do that, but it does the job for now.
