Paraview 脚本一例

Paraview 提供了一个 python 接口,可以用 python 脚本来控制 Paraview,以实现自动化的后处理。使用方法是,先写一个 python 脚本,里面包含调用 Paraview 的各种语句,然后,用 Paraview 的安装目录的 bin 下的 pvpython 来运行这个脚本即可。本篇用一个例子来说明 python 脚本的写法,以及常用 Paraview 操作对应的语句。

这个脚本实现的功能如下:

  1. 从指定路径中读取一个 “xxx.foam”
  2. 作一个截面,再在截面的基础上作矢量箭头
  3. 对截面使用 Surface Vector 这个 filter
  4. 对得到的 SurfaceVector 使用 Mask Points
  5. 使用 Stream Tracer With Custom Source,其中 Input 为 SurfaceVector,Seed point 为 MaskPoints,这样就得到了 slice 上的流线。
  6. 输出流线这个视图的一张屏幕截图
  7. 输出流场箭头叠加 slice 这个视图的 11 帧动画,动画输出过程中,Camera 是绕 y 轴旋转的,所以得到的是旋转效果的动画。

需要说明的是,以下脚本绝大部分都不是手写的,而是用 trace 功能自动生成的。打开一个空白的 Paraview,选择 Tools->Satrt Trace,然后,再去进行操作,Paraview 会将你的操作转换成 pvpython 语句,完成以后再 Tools->Stop Strace,就自动生成了一个脚本。

下面先给出脚本的全部,然后在脚本中给出注释,最后再给出一些额外的说明。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
try: paraview.simple
except: from paraview.simple import * ## 这是 python 的语法,注意 pvpython 是基于 python 的,使用的完全是 python 的语法
paraview.simple._DisableFirstRenderCameraReset()

pM_foam = OpenFOAMReader( FileName='E:\\OF_tutorials\\mapped\\pitzDailyMapped\\pM.foam' ) ## 用 OpenFOAMReader 读取一个 "xxx.foam" 文件

AnimationScene1 = GetAnimationScene() ## 获取动画操作的接口
AnimationScene1.EndTime = 0.1
AnimationScene1.PlayMode = 'Snap To TimeSteps'

pM_foam.CellArrays = ['U', 'UMean', 'UPrime2Mean', 'U_0', 'k', 'k_0', 'nuSgs', 'nuTilda', 'p', 'pMean', 'pPrime2Mean'] ## 获取可显示的场数据
pM_foam.MeshRegions = ['internalMesh']

RenderView1 = GetRenderView() ## 获取当前窗口的接口
RenderView1.CenterOfRotation = [0.10999999567866325, 0.0, 0.0]

RenderView1.Background = (81.0/255.0, 87.0/255.0, 110.0/255.0) ## 设置窗口的背景色,注意这里使用的RGB值是用 255 归一化的,即颜色值范围是 0~1
RenderView1.ViewSize = [1086,642] ## 设置窗口的大小
RenderView1.CameraViewAngle = 30 ## 设置相机的远近,这个值越大,相机越远
RenderView1.CenterAxesVisibility=0 ## 设置窗口旋转中心十字的显示,0 为不显示,1为显示

DataRepresentation1 = Show() ## 获取当前 source 的操作接口
#DataRepresentation1.ConstantRadius = 0.28999999165534973
DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation1.PointSpriteDefaultsInitialized = 1
DataRepresentation1.SelectionPointFieldDataArrayName = 'p'
DataRepresentation1.SelectionCellFieldDataArrayName = 'p'
DataRepresentation1.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation1.ScalarOpacityUnitDistance = 0.015162935987203615
DataRepresentation1.Texture = []
DataRepresentation1.ExtractedBlockIndex = 1
#DataRepresentation1.RadiusRange = [-0.07000000029802322, 0.28999999165534973]
DataRepresentation1.ScaleFactor = 0.0359999991953373

a1_p_PVLookupTable = GetLookupTableForArray( "p", 1, RGBPoints=[0.0, 0.0, 0.0, 1.0, 1e-16, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.498039, 0.498039, 0.498039], ColorSpace='HSV', ScalarRangeInitialized=1.0 )

a1_p_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1e-16, 1.0, 0.5, 0.0] )

DataRepresentation1.ScalarOpacityFunction = a1_p_PiecewiseFunction
DataRepresentation1.LookupTable = a1_p_PVLookupTable
#DataRepresentation1.RadiusRange = [-0.07, 0.29]

a1_p_PVLookupTable.ScalarOpacityFunction = a1_p_PiecewiseFunction

RenderView1.CameraPosition = [0.10999999567866325, 0.0, 0.7023592915690968]
RenderView1.CameraFocalPoint = [0.10999999567866325, 0.0, 0.0]
RenderView1.CameraClippingRange = [0.6943406986061459, 0.7141471810021238]
RenderView1.CameraParallelScale = 0.18178396116279658


######### generate a slice ################
Slice1 = Slice( SliceType="Plane" ) ## 作一个截面

Slice1.SliceOffsetValues = [0.0] ## 截面属性的设置,想必这种不需要解释,因为属性名字跟Paraview里是一样的
Slice1.SliceType.Origin = [0.11, 0.0, 0.0]
Slice1.SliceType = "Plane"

# toggle the 3D widget visibility.
#active_objects.source.SMProxy.InvokeEvent('UserEvent', 'ShowWidget')
#RenderView1.CameraClippingRange = [0.4287074803602159, 1.0485246743217493]

# toggle the 3D widget visibility.
active_objects.source.SMProxy.InvokeEvent('UserEvent', 'HideWidget') ## 这句在后面有说明
RenderView1.CameraClippingRange = [0.6943406986061459, 0.7141471810021238]

Slice1.SliceType.Normal = [0.0, 0.0, 1.0]

DataRepresentation2 = Show()
#DataRepresentation2.ConstantRadius = 0.28999999165534973
DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation2.PointSpriteDefaultsInitialized = 1
DataRepresentation2.SelectionPointFieldDataArrayName = 'p'
DataRepresentation2.SelectionCellFieldDataArrayName = 'p'
DataRepresentation2.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation2.Texture = []
DataRepresentation2.LookupTable = a1_p_PVLookupTable
#DataRepresentation2.RadiusRange = [-0.07000000029802322, 0.28999999165534973]
DataRepresentation2.ScaleFactor = 0.0359999991953373

DataRepresentation1.Visibility = 0 ## 把第一个source设置为不显示,对应着在 Paraview 里,将pipeline中 PM.foam 前面的“眼睛” 关掉

RenderView1.CameraClippingRange = [0.6953356986534058, 0.7128946809426333]

#DataRepresentation2.RadiusRange = [-0.07, 0.29]
DataRepresentation2.ColorArrayName = ('POINT_DATA', 'U') ## 将颜色显示改为用速度来显示。

a3_U_PVLookupTable = GetLookupTableForArray( "U", 3, RGBPoints=[0.0, 0.0, 0.0, 1.0, 16.0, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.498039, 0.498039, 0.498039], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1 ) ## 这里是设置速度的范围,以及速度与颜色的映射关系

a3_U_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 16.0, 1.0, 0.5, 0.0] )

AnimationScene1.AnimationTime = 0.1

ScalarBarWidgetRepresentation1 = CreateScalarBar( ComponentTitle='Magnitude', Title='U', Enabled=1, LabelFontSize=12, LookupTable=a3_U_PVLookupTable, TitleFontSize=12 )
GetRenderView().Representations.append(ScalarBarWidgetRepresentation1)


###### generate a glyph #################
Glyph1 = Glyph( GlyphType="Arrow", GlyphTransform="Transform2" ) ## 作流场箭头

DataRepresentation2.LookupTable = a3_U_PVLookupTable

a3_U_PVLookupTable.ScalarOpacityFunction = a3_U_PiecewiseFunction

Glyph1.Scalars = ['POINTS', 'p']
Glyph1.SetScaleFactor = 0.0359999991953373
Glyph1.Vectors = ['POINTS', 'U']
Glyph1.GlyphTransform = "Transform2"
Glyph1.GlyphType = "Arrow"

Glyph1.SetScaleFactor = 0.01
Glyph1.ScaleMode = 'off'
Glyph1.MaximumNumberofPoints = 1000

DataRepresentation3 = Show()
#DataRepresentation3.ConstantRadius = 0.2999996840953827
DataRepresentation3.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation3.PointSpriteDefaultsInitialized = 1
DataRepresentation3.SelectionPointFieldDataArrayName = 'p'
DataRepresentation3.SelectionCellFieldDataArrayName = 'p'
DataRepresentation3.ColorArrayName = ('POINT_DATA', 'U')
DataRepresentation3.Texture = []
#DataRepresentation3.RadiusRange = [-0.07000353187322617, 0.2999996840953827]
DataRepresentation3.ScaleFactor = 0.03700032159686089

#DataRepresentation3.ColorArrayName = ('POINT_DATA', '')

RenderView1.CameraClippingRange = [0.6936123081169067, 0.7150640745576737]

#DataRepresentation3.RadiusRange = [-0.0700035, 0.3]
DataRepresentation3.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation3.LookupTable = a1_p_PVLookupTable

DataRepresentation2.Texture = []
DataRepresentation2.Visibility = 0

ScalarBarWidgetRepresentation1.Enabled = 0
ScalarBarWidgetRepresentation1.Visibility = 0

a1_p_PVLookupTable.RGBPoints = [-96.12127685546875, 0.0, 0.0, 1.0, 61.768226623535156, 1.0, 0.0, 0.0]

a1_p_PiecewiseFunction.Points = [-96.12127685546875, 0.0, 0.5, 0.0, 61.768226623535156, 1.0, 0.5, 0.0]


###### generate a surface vector ###################
SetActiveSource(Slice1) ## 将截面这个 source 设置为当前的source ,即对应在 Paraview 里用鼠标选择 slice
SurfaceVectors1 = SurfaceVectors() ## 然后,在 slice 上使用 Surface Vectors 这个 fliter

SurfaceVectors1.SelectInputVectors = ['POINTS', 'U']

DataRepresentation4 = Show()
#DataRepresentation4.ConstantRadius = 0.28999999165534973
DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation4.PointSpriteDefaultsInitialized = 1
DataRepresentation4.SelectionPointFieldDataArrayName = 'p'
DataRepresentation4.SelectionCellFieldDataArrayName = 'p'
DataRepresentation4.ColorArrayName = ('POINT_DATA', 'U')
DataRepresentation4.Texture = []
DataRepresentation4.LookupTable = a3_U_PVLookupTable
#DataRepresentation4.RadiusRange = [-0.07000000029802322, 0.28999999165534973]
DataRepresentation4.ScaleFactor = 0.0359999991953373

#DataRepresentation4.RadiusRange = [-0.07, 0.29]

DataRepresentation3.Visibility = 0

RenderView1.CameraClippingRange = [0.6953356986534058, 0.7128946809426333]

DataRepresentation2.Texture = []

DataRepresentation2.Visibility = 0

RenderView1.CameraClippingRange = [0.002996152353161611, 2.9961523531616105]

DataRepresentation4.Visibility = 1

ScalarBarWidgetRepresentation1.Enabled = 1
ScalarBarWidgetRepresentation1.Visibility = 1

RenderView1.CameraPosition = [0.10999999567866325, 0.0, 0.702356634767752]
RenderView1.CameraClippingRange = [0.6953330684200745, 0.7128919842892683]
RenderView1.CameraParallelScale = 0.1817832735320095

DataRepresentation4.Texture = []


##### generate a maskpoint ##########################
MaskPoints1 = MaskPoints() ## 在 SurfaceVector1 的基础上使用 Mask Points 这个filter

MaskPoints1.GenerateVertices = 1
MaskPoints1.RandomSampling = 1
MaskPoints1.RandomSamplingMode = 'Spatially Stratified Random Sampling'
MaskPoints1.MaximumNumberofPoints = 1000

DataRepresentation5 = Show()
#DataRepresentation5.ConstantRadius = 0.28999999165534973
DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation5.PointSpriteDefaultsInitialized = 1
DataRepresentation5.SelectionPointFieldDataArrayName = 'p'
DataRepresentation5.SelectionCellFieldDataArrayName = 'p'
DataRepresentation5.ColorArrayName = ('POINT_DATA', 'U')
DataRepresentation5.Texture = []
DataRepresentation5.LookupTable = a3_U_PVLookupTable
#DataRepresentation5.RadiusRange = [-0.07000000029802322, 0.28999999165534973]
DataRepresentation5.ScaleFactor = 0.0359999991953373

DataRepresentation4.Visibility = 0

#DataRepresentation5.RadiusRange = [-0.07, 0.29]


####### generate stream line on a surface #########################
SetActiveSource(SurfaceVectors1) ## 选定 SurfaceVectors1,在此基础上,使用 Stream Tracer With Custom Source 这个 fliter。因此,这种情况下,Input 就等于 SurfaceVectors1 了
StreamTracerWithCustomSource1 = StreamTracerWithCustomSource( SeedSource=MaskPoints1 ) ## 本来这里括号里应该还需要指定 Input 的,但是上一句已经默认了 Input 为 SurfaceVectors1

StreamTracerWithCustomSource1.Vectors = ['POINTS', 'U']
StreamTracerWithCustomSource1.MaximumStreamlineLength = 0.35999999195337296

StreamTracerWithCustomSource1.MaximumError = 1e-06
StreamTracerWithCustomSource1.TerminalSpeed = 1e-12

DataRepresentation6 = Show()
#DataRepresentation6.ConstantRadius = 0.28999999165534973
DataRepresentation6.EdgeColor = [0.0, 0.0, 0.5000076295109483]
#DataRepresentation6.PointSpriteDefaultsInitialized = 1
DataRepresentation6.SelectionPointFieldDataArrayName = 'p'
DataRepresentation6.SelectionCellFieldDataArrayName = 'ReasonForTermination'
DataRepresentation6.ColorArrayName = ('POINT_DATA', 'U')
DataRepresentation6.Texture = []
DataRepresentation6.LookupTable = a3_U_PVLookupTable
#DataRepresentation6.RadiusRange = [-0.07000000029802322, 0.28999999165534973]
DataRepresentation6.ScaleFactor = 0.0359999991953373

DataRepresentation5.Visibility = 0

#DataRepresentation6.RadiusRange = [-0.07, 0.29]
DataRepresentation6.ColorArrayName = ('POINT_DATA', '')

ScalarBarWidgetRepresentation1.Enabled = 0
ScalarBarWidgetRepresentation1.Visibility = 0

MaskPoints1.MaximumNumberofPoints = 200

DataRepresentation6.Texture = []

DataRepresentation6.Opacity = 0.7
DataRepresentation6.DiffuseColor = [0.0, 0.0, 0.0]

DataRepresentation4.Texture = []

DataRepresentation4.Visibility = 1 ## 开启 SurfaceVectors1 的显示

RenderView1.CameraPosition = [0.10999999567866325, 0.0, 0.4797190320113051]
RenderView1.CameraClippingRange = [0.47492184169119206, 0.4869148174914747]

DataRepresentation2.Texture = []

DataRepresentation2.Visibility = 0

DataRepresentation4.Texture = []

WriteImage('E:/OF_tutorials/mapped/pitzDailyMapped/testscreen.png', Magnification=2) ## 将 SurfaceVectors1 和 stream line 叠加的视图输出为屏幕截图,截图大小为设置的窗口大小的两倍

DataRepresentation6.Visibility = 0

DataRepresentation4.Visibility = 0 ## 关闭 SurfaceVectors1 的显示

RenderView1.CameraClippingRange = [0.0026043054963398975, 2.6043054963398973]

DataRepresentation3.Texture = []

DataRepresentation3.Visibility = 1

RenderView1.CameraPosition = [0.11499807611107826, 0.00038802623748779297, 0.725254404116244]
RenderView1.CameraFocalPoint = [0.11499807611107826, 0.00038802623748779297, 0.0]
RenderView1.CameraClippingRange = [0.7162784695385823, 0.7383026137930281]
RenderView1.CenterOfRotation = [0.11499807611107826, 0.00038802623748779297, 0.0]
RenderView1.CameraParallelScale = 0.18770965232976394

DataRepresentation2.Texture = []

DataRepresentation2.Visibility = 1 ## 开启 slice 的显示

DataRepresentation3.Texture = []

DataRepresentation3.ColorArrayName = ('POINT_DATA', '')
DataRepresentation3.DiffuseColor = [0.0, 0.0, 0.0]

RenderView1.CameraPosition = [0.11499807611107826, 0.00038802623748779297, 0.599383805054747]
RenderView1.CameraClippingRange = [0.5916665764677003, 0.6105439557456087]

AnimationScene1.AnimationTime = 0.0
AnimationScene1.PlayMode = 'Sequence' ## 设置动画的播放模式
AnimationScene1.NumberOfFrames = 11

CameraAnimationCue1 = GetCameraTrack()
CameraAnimationCue1.AnimatedProxy = RenderView1
CameraAnimationCue1.Mode = 'Path-based' ## 设置 Camera 的旋转

TimeAnimationCue1 = GetTimeTrack()

KeyFrame5047 = CameraKeyFrame( FocalPathPoints=[0.114998, 0.000388026, 0.0], FocalPoint=[0.11499807611107826, 0.00038802623748779297, 0.0], PositionPathPoints=[0.0, 0.0, 0.5, 0.43120039439853625, 0.0, 0.40403042680054746, 0.6279812289875636, 0.0, 0.008529172380306538, 0.4444572181383874, 0.0, -0.39329526260513553, 0.016685579000083814, 0.0, -0.5035466293017314, -0.3382012405958345, 0.0, -0.24048906072285084, -0.35710462563060374, 0.0, 0.20085728982710624], ClosedPositionPath=1, ParallelScale=0.18770965232976394, Position=[0.11499807611107826, 0.00038802623748779297, 0.725254404116244] )

KeyFrame5048 = CameraKeyFrame( ParallelScale=0.18770965232976394, Position=[0.11499807611107826, 0.00038802623748779297, 0.725254404116244], KeyTime=1.0, FocalPoint=[0.11499807611107826, 0.00038802623748779297, 0.0] )

CameraAnimationCue1.KeyFrames = [ KeyFrame5047, KeyFrame5048 ]

RenderView1.CameraFocalPoint = [0.10459624231466369, 0.000388026, -0.002392362660596616]
RenderView1.CameraClippingRange = [0.5303500129360129, 0.7361458699228238]
RenderView1.CameraPosition = [-0.03455133768533633, -8.148545999999996e-05, 0.6026076373394033]

WriteAnimation('E:/OF_tutorials/mapped/pitzDailyMapped/ani/rotateTest.png', Magnification=2, Quality=2, FrameRate=15.000000) ## 输出动画,

Render()
一些细节:
  • 1
    active_objects.source.SMProxy.InvokeEvent('UserEvent', 'HideWidget')

语句的作用是,不显示 slice 的时候产生的哪个边框,即相当于 Paraview 里点掉 slice 的 “Show Plane”。

  • 1
    RenderView1.Background = (81.0/255.0, 87.0/255.0, 110.0/255.0)

作用是设置 RenderView1 的背景颜色。如果是直接在 Paraview 里以宏的形式运行脚本,那不需要这个,但若是用 pvpython 来运行脚本则需要,否则背景是黑色的。另外,这里的 RGB 颜色是用 255 归一化过的。

  • 颜色显示应该是以下几个语句的结果
    1
    2
    3
    4
    5
    a3_U_PVLookupTable = GetLookupTableForArray( "U", 3, RGBPoints=[0.0, 0.0, 0.0, 1.0, 16.0, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.498039, 0.498039, 0.498039], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1 )

    a3_U_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 16.0, 1.0, 0.5, 0.0] )

    DataRepresentation4.LookupTable = a3_U_PVLookupTable

至于 LookupTable 中,RGBPoints 的构建规则,细节不清楚。这种套用模板就好了,没必要自己手动写。

  • 相机的位置,即在 Paraview 里看到的图片的位置,旋转角度,远近等,由以下语句控制:
    1
    2
    3
    4
    5
    RenderView1.CameraPosition = [0.11499807611107826, 0.00038802623748779297, 0.725254404116244]
    RenderView1.CameraFocalPoint = [0.11499807611107826, 0.00038802623748779297, 0.0]
    RenderView1.CameraClippingRange = [0.7162784695385823, 0.7383026137930281]
    RenderView1.CenterOfRotation = [0.11499807611107826, 0.00038802623748779297, 0.0]
    RenderView1.CameraParallelScale = 0.18770965232976394

这些数据对不同算例是不一样的,需要根据特定情景来修改。没必要手动改,应该用 trace 功能来生成这些坐标值。

  • 关于相机选择部分,参考之前那篇讲添加旋转相机的。这些代码也应该用 trace 来生成,一般情况下没必要自找麻烦去手写。

最后附上一些上面脚本中没有涉及到,但可能会用到的功能:

  1. dir 用来查找一个对象所有可调用的函数,比如,假如 slice1 是一个 Slice 的对象,dir(slice1),则将列出所有 slice1 可以调用的函数或者成员。help(slice1) 类似,而且会列出每个函数的简短说明,这是 python 的特性。
  2. 关于动画时间的操作

    1
    2
    3
    4
    5
    6
    7
    animationScene1.GoToNext() ## 下一帧 

    animationScene1.Play() ## 播放动画

    animationScene1.GoToFirst() ## 跳到开始

    animationScene1.GoToLast() ## 跳到最后
  3. Hide, Show, Render
    Hide 和 Show 可以作用于 pipeline 里的每个条目,使其隐藏/可见,对应 paraview 关闭/点亮某个“眼睛”。Render 是当改变了某个显示属性后,要想显示出改变以后的效果需要调用的函数,相当于 Paraview 里点 Apply。

  4. setActiveSource,getActiveSource,setActiveView,getActiveView
    这四个,作用分别是,将某个 pipeline设为选定状态,相当于鼠标选中某个 pipeline;获取当前选定的 pipeline;将某个 窗口设为选定状态(针对有多个窗口的情形);返回当前选定的窗口。此外,还有很多对 pipeline 和 窗口进行操作的接口,需要时查即可。
  5. pvpython 本质上就是 python,所以,python 的语法都可以用。比如,下面是一个循环删除所有 pipeline 的方法

    1
    2
    3
    4
    for key in GetSources().keys():
    s = GetSources()[key]
    Delete(s)
    del s
  6. Paraview 的 python shell(Tools->Python Shell),可以当作是一个 pvpython 的 IDE,里面可以方便地进行命令补全,并且每条语句的效果可以即时地显示在 Paraview 中,调试脚本的时候非常有用。

    最后说明一下,上述脚本只适用于 Paraview-4.1,在 Paraview-5.0 以后,接口的名字有所变化,这里给出一个链接,感兴趣的读者可以在链接中找到本文中介绍的脚本以及另一个适用于 Paraview-5.0 的脚本。

参考:

  1. http://www.paraview.org/Wiki/ParaView/Python_Scripting
  2. http://www.paraview.org/Wiki/Python_recipes
  3. http://www.paraview.org/ParaView/Doc/Nightly/www/py-doc/index.html