GregNash
GregNash

Reputation: 1336

How do I use ParaView's CSVReader in a Python Script?

How do I use ParaView's CSVReader in a Python Script? An example would be appreciated.

Upvotes: 0

Views: 631

Answers (3)

Bruce_Warrior
Bruce_Warrior

Reputation: 1181

Improving the @GregNash's answer. If you want to include only a single file (called foo.csv):

outcsv = CSVReader(FileName= 'foo.csv')

Or if you want to include all files with certain pattern use glob. For example if files start with string foo (aka foo.csv.0, foo.csv.1, foo.csv.2):

myreader = CSVReader(FileName=glob.glob('foo*'))

To use glob is neccesary import glob in the preamble. In general in Filename you could work with strings generated with python which could contain more complex pattern files and file's path.

Upvotes: 1

GregNash
GregNash

Reputation: 1336

If you have a .csv file that looks like this:

x,y,z,attribute
0,0,0,0
1,0,0,1
0,1,0,2
1,1,0,3
0,0,1,4
1,0,1,5
0,1,1,6
1,1,1,7

then you can import it with a command that looks like this:

myReader = CSVReader(FileName='C:\foo.csv', guiName='foo.csv')

Also, if you don't add that guiName parameter, you can change the name later using the RenameSource command like this:

RenameSource(proxy = myReader, newName = 'MySuperNewName'

Credit for the renaming part of this answer to Sebastien Jourdain.

Upvotes: 2

CaringDev
CaringDev

Reputation: 8551

Unfortunately, I don't know Paraview at all. But I found "... simply record your work in the desktop application in the form of a python script ..." at their site. If you import a CSV like that, it might give you a hint.

Upvotes: 1

Related Questions