[Paraview] question on using python programmable source

Sreejith Kuttanikkad sreejithpk at gmail.com
Thu May 29 16:08:07 EDT 2008


On Thu, May 29, 2008 at 9:43 PM, Jean Favre <jfavre at cscs.ch> wrote:

> May I suggest the use of the python glob module.
> I have just tried it inside a programmable source and it works fine.
> Glob will look for all filenames following a pattern. You might also
> want to sort them alphabetically after you have created the array
>
> here is an example
>
> import glob
>
> files = glob.glob("file*.dat")  # creates the array you wanted
> files.sort()                         # sorts them
>
> i = 0
> while i < len(files):
>     print files[i]
>     i = i +
>

Thank you Robert and Jean.
Jean's idea indeed solved the file handling problem.
But now i found that the script is able to show only one curve at  a time,
i.e the last one in the file*.dat,  eventhough it reads all the files.
How do I solve the issue.? or is it that for each file I have to have
different programmable filter.
Here is the script I used.. It would be great if some one can help me in
this regard.
thanks in advance.
Sreejith

#!/usr/bin/python
import string, sys, math,glob
pdo = self.GetPolyDataOutput()
FILES=glob.glob("file_name*.dat")
FILES=sort()
for filename in FILES:
   file=open(filename,'r')
   point=0
   #This will store the points for the lines
   newPts = paraview.vtkPoints()
   for line in file:
      #read x,y,z values
      x = float( line.split()[0] )
      y = float( line.split()[1] )
      if(len(line.split())==3): # in 3D
         z = float( line.split()[2] )
      else:
         z=0.0 # in 2D

      newPts.InsertPoint(point, x,y,z)
      point+=1

   pdo.SetPoints(newPts)
   aPolyLine = paraview.vtkPolyLine()
   aPolyLine.GetPointIds().SetNumberOfIds(point)
   for i in range(0,point):
        aPolyLine.GetPointIds().SetId(i, i)
        pdo.Allocate(1, 1)
        pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
file.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20080529/3ce9a7f1/attachment.htm>


More information about the ParaView mailing list