[Paraview] Collaboration between "Python Shell" and "Programmable Source Python Script"
Hal Canary
hal at cs.unc.edu
Sun May 12 18:46:06 EDT 2013
On 05/12/2013 07:43 AM, Сергей Дмитриев wrote:
> Hello.
> I make the following data from the "Python Shell" in "Programmable Source"
> In the "Python Shell" I write the following:
>
> src=ProgrammableSource()
> src.add_attribute('MyArray',[1,2,3])
> Show()
>
> In the ProgrammableSource Script I write the following:
>
> array=self.MyArray
> print array
> ######
>
> Result:
>
> Traceback (most recent call last):
> File "<string>", line 24, in <module>
> File "<string>", line 2, in RequestData
> AttributeError: Array
>
> How to pass an array between the two interpreters?
I would directly insert my array into the source filter. The following
example is a ParaView macro:
script = """
pdo = self.GetPolyDataOutput()
newPts = vtk.vtkPoints()
for x in [(1,1,1),(0,0,1),(0,1,0),(1,0,0)]:
newPts.InsertNextPoint(x)
lines = vtk.vtkCellArray()
for c in [[0,1,2,3,0],[0,2],[1,3]]:
lines.InsertNextCell(len(c))
for i in c:
lines.InsertCellPoint(i)
pdo.SetLines(lines)
pdo.SetPoints(newPts)
assert len(array) == pdo.GetNumberOfPoints()
varray = vtk.vtkDoubleArray();
varray.SetName(%r)
for x in %r:
varray.InsertNextValue(x)
pdo.GetPointData().AddArray(varray)
"""
name = "myarray"
array = [1,2,3,4]
src = ProgrammableSource(
OutputDataSetType='vtkPolyData',
Script=(script % (name, array)))
Show(src)
More information about the ParaView
mailing list