我想从vtk / vtu文件中自动导出csv文件。
现在,我采取的步骤是:
这为每个时间步执行一个csv文件,名称为basefilename#timestepno#.csv
有没有办法从命令行执行此操作(计算机上没有X服务器进行计算),例如使用python接口?
答案 0 :(得分:9)
在UI中的Python Shell或使用 pvpython 或 pvbatch Python可执行文件中尝试以下操作。
from paraview import simple
reader = simple.OpenDataFile("..../foo.pvd")
writer = simple.CreateWriter("..../foo.csv", reader)
writer.WriteAllTimeSteps = 1
writer.FieldAssociation = "Points"
writer.UpdatePipeline()
答案 1 :(得分:4)
我遇到了与pvtu文件类似的问题,并使用下面的脚本解决了这个问题。我在Paraview中使用execfile(“SCRIPTNAME”)运行脚本 - >工具 - > Python Shell。我希望这会有所帮助。
- 莱因哈德
from paraview.simple import *
import os
"""Function that counts number of files
with specific extension in directory """
def directory(path,extension):
list_dir = []
list_dir = os.listdir(path)
count = 0
for file in list_dir:
if file.endswith(extension): # eg: '.txt'
count += 1
return count
"""Choose input/output directory and filenames"""
pvtu_input_directory = "thin_1000_0.4/mesh/"
csv_output_directory = "thin_1000_0.4/csv/"
input_filename_root = "output"
output_filename_root = "output"
""" Create output directory """
os.system('mkdir '+csv_output_directory)
"""Start Loop over all files """
number_of_pvtu = directory(pvtu_input_directory,'.pvtu')
for index in range(1,number_of_pvtu):
in_filename = input_filename_root + "%0.4d" % index+".pvtu"
out_filename = output_filename_root + "%0.4d" % index +".csv"
loadfile = pvtu_input_directory + in_filename
writefile = csv_output_directory + out_filename
r = XMLPartitionedUnstructuredGridReader( FileName=loadfile)
writer = CreateWriter(writefile,r)
writer.FieldAssociation = "Points"
writer.UpdatePipeline()
""" That's it. """"