如何解决如何使用SaveData在ParaView 3.98.1中写入ASCII文件?
我正在为一个旧项目编写自动化脚本,我需要Paraview 3.98.1中的pvpython
方面的帮助。此版本中的功能SaveData()
不存在。我找到了其实现here,并将其移至我的代码中。如何将文件另存为ASCII?像SaveData(filename,proxy=px,FileType='Ascii')
一样调用它会将我的文件另存为二进制文件(笨拙的行为)。
我需要此版本,因为脚本管道中的某些代码可以处理非常具体的vtk
文件。使用最新版本的SaveData()
函数最终会在最终文件中创建不同的元数据,而当我处理它们时,最终会破坏我的结果。目前,使用旧版的Paraview比修改我的所有代码都容易。
修改:
该网站现在无法正常运行,但昨天才运行。也许是内部问题?无论如何,代码附在下面。
# -----------------------------------------------------------------------------
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,**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
# -----------------------------------------------------------------------------
解决方法
here(也是我的帖子)回答了问题。我使用SaveData()将二进制文件与所需的代理一起保存,然后使用DataSetWriter()将FileType更改为ASCII。这不是一个漂亮的解决方案,因为SaveData()应该这样做,但是它确实可以完成工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。