You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Paraview中如何在ProgrammableSource获取当前时间索引

解决方案

在ParaView的ProgrammableSource中,可直接使用内置的timestep变量获取当前动画的时间步索引(从0开始计数),用它替换代码中固定的[2],就能实现随时间步输出对应行的功能。

修改后的代码如下:

import numpy as np

file = "table.csv"
tbl = np.genfromtxt(file, names=True, delimiter=",", autostrip=True)
# 获取当前时间步索引,替换固定行索引2
current_step = timestep
# 防止时间步索引超出数组行数范围
if current_step >= len(tbl):
    current_step = len(tbl) - 1

for n in tbl.dtype.names:
    v = tbl[n][current_step]
    output.RowData.append(v, n)

说明

  • timestep是ParaView为ProgrammableSource提供的内置变量,自动对应当前动画的时间步序号,从0开始递增。
  • 添加的判断逻辑是为了避免时间步索引超出数组行数引发报错,提升程序鲁棒性。

内容的提问来源于stack exchange,提问作者Nobody-86

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 19:10:31