<div dir="ltr">Can't you just use the pvpython or pvbatch if you need to run on the command line?  I'm not sure what could be your problem other than if you are using a different python to what paraview is compiled against.<div>
<br></div><div>Regards,</div><div>Paul</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 6 March 2014 19:46, Simon Couture <span dir="ltr"><<a href="mailto:simon-2.couture@polymtl.ca" target="_blank">simon-2.couture@polymtl.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for your help Paul. I think I narrowed down my problem. Your example<br>
(and also my own) indeed work when executed from the paraview GUI's python<br>
shell. However, when I try to run your example from an external python shell<br>
(outside the paraview GUI), this is what I get:<br>
<br>
In [5]: from paraview.simple import *<br>
paraview version 3.98.1<br>
<br>
In [6]: paraview<br>
Out[6]: <module 'paraview' from<br>
'/raid/usr/local/lib/paraview-3.98/site-packages/paraview/__init__.py'><br>
<br>
In [7]: Sphere1 = Sphere( guiName="Sphere1" )<br>
<br>
In [8]: ProgrammableFilter1 = ProgrammableFilter( guiName="ProgrammableFilter1",<br>
<div class="">RequestUpdateExtentScript='', RequestInformationScript='', Script="input =<br>
self.GetInput()\noutput = self.GetOutput()\noutput.ShallowCopy(input)\n\nnp =<br>
output.GetNumberOfPoints()\n\narray =<br>
vtk.vtkFloatArray()\narray.SetName('newArray')\narray.SetNumberOfTuples(np)\nfor<br>
i in range(np):\n    array.SetValue(i,<br>
i)\n\noutput.GetPointData().AddArray(array)\n", PythonPath='' )<br>
<br>
</div>In [9]: UpdatePipeline()<br>
Traceback (most recent call last):<br>
  File "<string>", line 1, in <module><br>
ImportError: No module named paraview<br>
<br>
In [10]: paraview<br>
Out[10]: <module 'paraview' from<br>
'/raid/usr/local/lib/paraview-3.98/site-packages/paraview/__init__.py'><br>
<br>
In [11]: ProgrammableFilter1.PointData.GetNumberOfArrays()<br>
Out[11]: 0<br>
<br>
I make sure that my python path contains all the directories that are present in<br>
the paraview GUI's python shell session. Indeed I can type 'import paraview' or<br>
'import paraview.simple' (as above) with no problem, but somehow I get this<br>
weird ImportError when updating the pipeline with the programmable filter. Any<br>
ideas on how to get to the bottom of this? This is on Linux CentOS and using<br>
either python 2.6 or 2.7 yields this error.<br>
<span class="HOEnZb"><font color="#888888"><br>
Simon<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
Quoting Paul Edwards <<a href="mailto:paul.m.edwards@gmail.com">paul.m.edwards@gmail.com</a>>:<br>
<br>
> Are you sure you are updating?  This works for me in pvpython:<br>
><br>
> >>> from paraview.simple import *<br>
> paraview version 4.1.0-243-gd6a42b6<br>
> >>> Sphere1 = Sphere( guiName="Sphere1" )<br>
> >>><br>
> >>> ProgrammableFilter1 = ProgrammableFilter(<br>
> guiName="ProgrammableFilter1", RequestUpdateExtentScript='',<br>
> RequestInformationScript='', Script="input = self.GetInput()\noutput =<br>
> self.GetOutput()\noutput.ShallowCopy(input)\n\nnp =<br>
> output.GetNumberOfPoints()\n\narray =<br>
><br>
vtk.vtkFloatArray()\narray.SetName('newArray')\narray.SetNumberOfTuples(np)\nfor<br>
> i in range(np):\n    array.SetValue(i,<br>
> i)\n\noutput.GetPointData().AddArray(array)\n", PythonPath='' )<br>
> >>> UpdatePipeline()<br>
> >>> ProgrammableFilter1.PointData.GetNumberOfArrays()<br>
> 2<br>
><br>
> Regards,<br>
> Paul<br>
><br>
><br>
><br>
> On 6 March 2014 01:31, Simon Couture <<a href="mailto:simon-2.couture@polymtl.ca">simon-2.couture@polymtl.ca</a>> wrote:<br>
><br>
> > Hi everyone,<br>
> ><br>
> > I am trying to use paraview from an external python program where I import<br>
> > paraview.simple and mostly use python code generated by Paraview's trace<br>
> > tool<br>
> > to accomplish what I want. In general it works well, but in one instance I<br>
> > need<br>
> > to generate a new data array from my source/reader, and as far as I know,<br>
> > the<br>
> > programmable filter is the only way to do this (the actual PointData<br>
> > arrays of<br>
> > the sources are not directly visible/editable through the python shell).<br>
> > Now<br>
> > when I try to execute the python code that I get from trace to insert a<br>
> > programmable filter with a given script, the PointData array that the<br>
> > programmable filter's script is supposed to create is not created (and it<br>
> > does<br>
> > work when I create the programmable filter using the Paraview GUI).<br>
> ><br>
> > To be more clear, here is the python code that I run (cutting out camera<br>
> > and<br>
> > rendering commands):<br>
> ><br>
> > mysource = AVSUCDReader( FileNames=['/home/myfile.inp'] )<br>
> ><br>
> > mysource.PointArrayStatus = []<br>
> > mysource.CellArrayStatus = []<br>
> ><br>
> > RenderView1 = GetRenderView()<br>
> > DataRepresentation3 = Show()<br>
> > ProgrammableFilter1 = ProgrammableFilter()<br>
> > DataRepresentation4 = Show()<br>
> > ProgrammableFilter1.RequestUpdateExtentScript = ''<br>
> > ProgrammableFilter1.PythonPath = ''<br>
> > ProgrammableFilter1.RequestInformationScript = ''<br>
> > ProgrammableFilter1.Script = "pdi = self.GetInput()\nnbpoints =<br>
> > pdi.GetNumberOfPoints()\ninput_pointdata =<br>
> > pdi.GetPointData().GetArray('data')<br>
> > [... the rest of my script here]"<br>
> ><br>
> > After running this in either the paraview python shell or from an external<br>
> > python program, if I do for instance:<br>
> ><br>
> > ProgrammableFilter1.PointData.GetNumberOfArrays()<br>
> ><br>
> > I get 0 meaning that no PointData array was created, whereas if the same<br>
> > programmable filter is created in the paraview GUI, I would get 1. Please<br>
> > note<br>
> > that I am not using the Copy Arrays option of the programmable filter.<br>
> ><br>
> > Has anyone successfully used the programmable filter from a python script?<br>
> ><br>
> > _______________________________________________<br>
> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
> ><br>
> > Visit other Kitware open-source projects at<br>
> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
> ><br>
> > Please keep messages on-topic and check the ParaView Wiki at:<br>
> > <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a><br>
> ><br>
> > Follow this link to subscribe/unsubscribe:<br>
> > <a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a><br>
> ><br>
><br>
<br>
<br>
<br>
</div></div></blockquote></div><br></div>