Paraview:NameError:name'输入'没有定义

时间:2014-12-31 02:16:15

标签: python paraview

我尝试使用Python在Paraview中创建ProgrammableFilter。过滤器应该采用当前选定的点并对它们进行计数(过滤器将更加精细,但这足以解释我的问题)。

在我的代码中,我没有使用任何名为' inputs'的变量,但是当我执行它时,我得到了这个输出(注意最后有一个错误,代码似乎是执行两次):

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个步骤,第一个是&#34; Sphere源&#34;第二个是带有此代码的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)

你知道造成我问题的原因吗?

1 个答案:

答案 0 :(得分:0)

经过一些工作后,我发现如何在Paraview中访问选定的点而不会产生上面提到的奇怪错误。

以下是代码:

import paraview
import paraview.simple

proxy = paraview.simple.GetActiveSource()

if proxy is None:
    print "Proxy is None" 
    return

active_selection = proxy.GetSelectionInput(proxy.Port)

if active_selection is None:
    print "No selection is active" 
    return

print "Selected points: %s" % (active_selection.IDs)
print "Amount of points: %s" % (len(active_selection.IDs) / 2)

如果我在Sphere Source中选择6个点,那么这就是输出:

Selected points: [0, 14, 0, 15, 0, 16, 0, 20, 0, 21, 0, 22]
Amount of points: 6

您可以看到每个选定的点生成2个ID,第一个是&#34;进程ID&#34;第二个是你的观点的实际ID。

无论如何,原始错误的原因对我来说仍然不清楚。