Error in save vtkParametricFunctionSource using vtkPolyDataWriter

I am working on a project which need to save data into .vtk file using python. I got an error when save a vtkParametricFunctionSource. Here is a sample code.

import vtk
ellipsoid = vtk.vtkParametricEllipsoid()
ellipsoid.SetXRadius(1)
ellipsoid.SetYRadius(1)
ellipsoid.SetZRadius(1)
ellipsoidSource = vtk.vtkParametricFunctionSource()
ellipsoidSource.SetParametricFunction(ellipsoid)
ellipsoidSource.SetOutputPointsPrecision(5)
ellipsoidSource.Update()

writer = vtk.vtkPolyDataWriter()
writer.SetInputData(ellipsoidSource.GetOutput())# fail
# writer.SetInputConnection(ellipsoidSource.GetOutputPort()) # also fail and get same result
writer.SetFileName('ellipsoid.vtk')
writer.Update()

The program report:‘SetInputData argument 1: method requires a VTK object’. I cannot figure out the reason behind it. Please help me, thanks.

Your example works perfectly for me, creating a .vtk file with this polydata:

image

The SetInputData argument 1: method requires a VTK object error message indicates that VTK has not been imported correctly into your Python environment. If you provide more information about how did you get VTK (did you build it or pip-installed), which VTK and Python distribution and version you used, etc. then dgobbi or ben.boeckel may be able to help you.

I can also confirm that it works for me. You most likely need to set up your Python environment.