[Paraview] Programmable filter from external python program

Paul Edwards paul.m.edwards at gmail.com
Thu Mar 6 06:59:48 EST 2014


Are you sure you are updating?  This works for me in pvpython:

>>> from paraview.simple import *
paraview version 4.1.0-243-gd6a42b6
>>> Sphere1 = Sphere( guiName="Sphere1" )
>>>
>>> ProgrammableFilter1 = ProgrammableFilter(
guiName="ProgrammableFilter1", RequestUpdateExtentScript='',
RequestInformationScript='', Script="input = self.GetInput()\noutput =
self.GetOutput()\noutput.ShallowCopy(input)\n\nnp =
output.GetNumberOfPoints()\n\narray =
vtk.vtkFloatArray()\narray.SetName('newArray')\narray.SetNumberOfTuples(np)\nfor
i in range(np):\n    array.SetValue(i,
i)\n\noutput.GetPointData().AddArray(array)\n", PythonPath='' )
>>> UpdatePipeline()
>>> ProgrammableFilter1.PointData.GetNumberOfArrays()
2

Regards,
Paul



On 6 March 2014 01:31, Simon Couture <simon-2.couture at polymtl.ca> wrote:

> Hi everyone,
>
> I am trying to use paraview from an external python program where I import
> paraview.simple and mostly use python code generated by Paraview's trace
> tool
> to accomplish what I want. In general it works well, but in one instance I
> need
> to generate a new data array from my source/reader, and as far as I know,
> the
> programmable filter is the only way to do this (the actual PointData
> arrays of
> the sources are not directly visible/editable through the python shell).
> Now
> when I try to execute the python code that I get from trace to insert a
> programmable filter with a given script, the PointData array that the
> programmable filter's script is supposed to create is not created (and it
> does
> work when I create the programmable filter using the Paraview GUI).
>
> To be more clear, here is the python code that I run (cutting out camera
> and
> rendering commands):
>
> mysource = AVSUCDReader( FileNames=['/home/myfile.inp'] )
>
> mysource.PointArrayStatus = []
> mysource.CellArrayStatus = []
>
> RenderView1 = GetRenderView()
> DataRepresentation3 = Show()
> ProgrammableFilter1 = ProgrammableFilter()
> DataRepresentation4 = Show()
> ProgrammableFilter1.RequestUpdateExtentScript = ''
> ProgrammableFilter1.PythonPath = ''
> ProgrammableFilter1.RequestInformationScript = ''
> ProgrammableFilter1.Script = "pdi = self.GetInput()\nnbpoints =
> pdi.GetNumberOfPoints()\ninput_pointdata =
> pdi.GetPointData().GetArray('data')
> [... the rest of my script here]"
>
> After running this in either the paraview python shell or from an external
> python program, if I do for instance:
>
> ProgrammableFilter1.PointData.GetNumberOfArrays()
>
> I get 0 meaning that no PointData array was created, whereas if the same
> programmable filter is created in the paraview GUI, I would get 1. Please
> note
> that I am not using the Copy Arrays option of the programmable filter.
>
> Has anyone successfully used the programmable filter from a python script?
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20140306/c11c19c9/attachment.html>


More information about the ParaView mailing list