【发布时间】:2015-02-27 04:48:45
【问题描述】:
我正在尝试使用 Python 在 Paraview 中创建 ProgrammableFilter。过滤器应该取当前选择的点并计算它们(过滤器会更详细,但这足以解释我的问题)。
在我的代码中,我没有使用任何名为“输入”的变量,但是当我执行它时,我得到了这个输出(注意最后有一个错误,代码似乎被执行了两次):
Generated random int: 13 using time 1419991906.3
13 Execution start
13 Selection is active
Generated random int: 59 using time 1419991906.34
59 Execution start
59 No selection is active
59 Execution end
13 Extr_Sel_raw was not None
13 Number of cells: 44
13 Execution end
Traceback (most recent call last):
File "<string>", line 22, in <module>
NameError: name 'inputs' is not defined
代码如下,我的管道有2个步骤,第一个是“Sphere source”,第二个是带有此代码的ProgrammableFilter:
import paraview
import paraview.simple
import paraview.servermanager
import random
import time
a = time.time()
random.seed(a)
#time.sleep(1)
tmp_id = random.randint(1,100)
print "\nGenerated random int: %s using time %s" % (tmp_id, a)
print "%s Execution start" % (tmp_id)
proxy = paraview.simple.GetActiveSource()
active_selection = proxy.GetSelectionInput(proxy.Port)
if active_selection is None:
print "%s No selection is active" % (tmp_id)
else:
print "%s Selection is active" % (tmp_id)
Extr_Sel = paraview.simple.ExtractSelection(Selection=active_selection)
Extr_Sel_raw = paraview.servermanager.Fetch(Extr_Sel)
if Extr_Sel_raw is None:
print "%s Extr_Sel_raw was None" % (tmp_id)
else:
print "%s Extr_Sel_raw was not None" % (tmp_id)
print "%s Number of cells: %s" % (tmp_id, Extr_Sel_raw.GetNumberOfCells())
pdi = self.GetPolyDataInput()
pdo = self.GetPolyDataOutput()
pdo.SetPoints(pdi.GetPoints())
print "%s Execution end\n" % (tmp_id)
你知道是什么导致了我的问题吗?
【问题讨论】:
-
您是否尝试过查找第 22 行(调用输入的行)?
-
这不是我的代码的第22行,如果你看到输出,我的代码的最后一行正在成功执行(它会打印一条消息)
-
确实!我的预感是 paraview 脚本之一的第 22 行正在调用某些对象
inputs,在某些情况下该对象未定义。 -
你知道我如何检查 Paraview 的哪个脚本是那个吗?
-
强烈建议不要在可编程过滤器中使用 paraview.simple 或 paraview.servermanager,也不支持。无需赘述,只要说数据处理管道不能混合客户端控制代码就足够了。