[Paraview] question on using python programmable source
Berk Geveci
berk.geveci at kitware.com
Fri May 30 08:44:14 EDT 2008
You have to take the creation of vtkPoints() outside the main loop
otherwise you will add the points for the last cell only. Also, you
should probably not call Allocate() inside the loop.
-berk
On Thu, May 29, 2008 at 4:08 PM, Sreejith Kuttanikkad
<sreejithpk at gmail.com> wrote:
>
>
> 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()
>
>
>
>
>
> _______________________________________________
> ParaView mailing list
> ParaView at paraview.org
> http://www.paraview.org/mailman/listinfo/paraview
>
>
More information about the ParaView
mailing list