# VeloView 的 Python 控制台编程 ## 启动方式 VeloView 提供了两种与 Python 脚本互动的方法。 第一种方法是在命令行或 cmd 中输入: ```bash VeloView –script path_to_my_script ``` 即可启动 VeloView 并运行脚本。 第二种方法是打开 VeloView 后,打开 python shell,方法如图: ## 使用示例 ### 生成一个圆锥体 比较常用的是 simple module,shell 打开以后会自动导入 ```python from paraview.simple import * #这句自动会加上 #生成一个圆锥object, 分辨率=32,中心[X,Y,Z]移动到[1,2,3] cone = Cone(Resolution=32, Center = [1, 2, 3]) #增加一个缩小过滤器 shrinkFilter = Shrink(cone) #设定为显示 Show(shrinkFilter) #渲染所有物体 Render() ``` 其他 Simple Module 中比较好用的东西: ```python help(Cone()) #直接显示help文档,相当的有用,谁用谁知道。。。 ``` 各种形状: ```python Arrow() # 箭头 Sphere() # 球体 Box() # 立方体盒子(和前面几个有点不同) Cylinder() # 圆柱体 Disk() # 圆环(没有高度的光盘形状) Line() # 线段 Tube() # 管子 ``` 功能: ```python Hide() # 隐藏对象 HideAll() # 隐藏全部对象 Delete() # 删除对象 Render() # 渲染 ``` ### 导入一个3D模型 从 obj 文件中导入一个 3D 模型 ```python from paraview.simple import * #打开3D模型文件 Carfile = OpenDataFile("C:/文件路径/文件名.obj") #对3D模型进行变形 carmodel = Transform(Carfile) #旋转[X,Y,Z] carmodel.Transform.Rotate = [90,0,90] #位移[X,Y,Z] carmodel.Transform.Translate = [0,-1,-1.8] #切换显示 Show(carmodel) #渲染 Render() ``` ## 参考资料 - [ParaView’s Python说明](https://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/index.html) - [ParaView Python脚本的另一个版本,用上面那个比较靠谱,这个有参考价值](https://www.vtk.org/Wiki/index.php?title=ParaView/Python_Scripting&redirect=no) - [simple 模块的说明](https://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.simple.html) - [在VeloView中进行Python编程](https://blog.csdn.net/seeseeatre/article/details/79746859)