Hi all,

I am trying to create a programmable source to create a sphere, the location of which updates per time step based on coordinates in a csv file. However, I have sort of got my head around the python library (thanks to tracing what I do in the GUI!), but I think one needs to use the vtk library instead? I have written a python script which does the job when called from the python shell, but this is not updating when the timestep changes. I have tried adapting this code to work as a programmable source, but to no avail.

Here is the code for the programmable source I have so far:

import vtk
import os
import csv

csvfilename = '../../resources/vtk/testpos.csv'
csvfilename= os.path.abspath(csvfilename)

animationScene1 = GetAnimationScene()
target = int(animationScene1.AnimationTime)
print "Target value is: " + str(target)

pos = [0.0, 0.0, 0.0]
count=0
with open(csvfilename) as f:
    r = csv.reader(f)
    for row in r:
        print "Current row :" + str(row)
        if count == target:
            print "found it"
            pos = [float(i) for i in row]
            break
        count += 1
print "Pos is now : " + str(pos)

s=vtk.vtkSphereSource()
s.SetCenter(pos)
s.SetRadius(10)
s.Update()


The csv stuff works as far as I can tell, but it gives an error because GetAnimationScene is not defined. However, there is another problem, even if I ignore all of the time dependent things and just try to create a sphere in this manner:

import vtk
s=vtk.vtkSphereSource()
s.SetCenter([0,0,0])
s.SetRadius(10)
s.Update()

there are no errors, but no sphere either! So I guess I am missing something fundamental about the difference between python scripting and programmable sources. Further, I wonder if it would be easier to change the position of an already created sphere source with a programmable filter instead?

Has anybody solved a similar problem and can point me in the correct direction? Any help would be greatly appreciated.

Kind regards,

James
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to