Paraview python 中的 SaveData 不保存文件 编辑

问题描述

我使用一个 stl 文件使用 Paraview 拆分 stl。我在paraview中使用python trace跟踪了该方法

现在,我使用python中的代码来运行它。它运行完美,但它不会根据需要保存分割的网格。该代码根据从 paraview 获得的跟踪使用。下面是使用 SaveData 保存文件代码片段。如何保存stl文件

import sys  #sys- append path
import numpy as np

ParaviewBuildpath = "/home/Paraview-5.7.0/"
sys.path.append(ParaviewBuildpath + "lib/") 
sys.path.append(ParaviewBuildpath + "lib/python3.7/site-packages")
sys.path.append(ParaviewBuildpath + "lib/python3.7/site-packages/vtkmodules")

from paraview.simple import *   
import vtk
# find source
mesh176_rightstl = FindSource('mesh176_right.stl')
generateSurfacenormals1 = GenerateSurfacenormals(Input=mesh176_rightstl)
# Properties modified on generateSurfacenormals1
generateSurfacenormals1.FeatureAngle = 15.0
# create a new 'Connectivity'
connectivity1 = Connectivity(Input=generateSurfacenormals1)

# create a new 'Threshold' 
threshold1 = Threshold(Input=connectivity1)
#threshold1.Scalars = ['POINTS','RegionId']

# Properties modified on threshold1
threshold1.ThresholdRange = [10.0,982.0]

# create a new 'Extract Surface'
extractSurface1 = ExtractSurface(Input=threshold1)

# save data
SaveData('surf176.stl',proxy=extractSurface1,FileType='Ascii')

我已经从“generateSurfacenormals1”行中解决了我面临的错误

[paraview]vtkDemandDrivenPipeline:713 ERR| vtkPVCompositeDataPipeline (0x556f782fe7c0):算法 vtkPpolyDatanormals(0x556f7a16b2a0) 的输入端口 0 有 0 个连接但不是可选的。

如何克服这个错误

任何线索将不胜感激。

问候, Sunag R A.

解决方法

错误消息意味着 mesh176_rightstl 为 None,因此 FindSource 找不到任何内容。源名称是否正确?数据是否正确加载?

当出现错误时,脚本停止并且不调用 SaveData。但它的语法是正确的。

测试stl编写器的最少代码:

s = Sphere()
SaveData('sphere.stl',proxy = s,FileType='Ascii')

使用 ParaView 5.9 正确生成 stl 文件

编辑

您应该取消注释该行

#threshold1.Scalars = ['POINTS','RegionId']

因为在您要求之前不会执行管道(例如使用 SaveData),所以在您创建阈值时找不到默认数组。