how can I get the part of ConnectivityFilter,and save it as an stl file.

Hi, i am using vtk.vtkPolyDataConnectivityFilter() as a filter to segment a stl file(or the demo ,vtkFiltersSources), when i use it as the result, I can show it ,but I cannot save it as an stl file.
how can I solve this problem. and I also find there is some error when I use the same code for connectivetyfilter.

‘’’
connectivityFilter = vtkConnectivityFilter()
connectivityFilter.SetInputConnection(appendFilter.GetOutputPort())
connectivityFilter.SetExtractionModeToAllRegions()
connectivityFilter.ColorRegionsOn()
connectivityFilter.Update()

connectivityFilter.SetExtractionModeToSpecifiedRegions()
connectivityFilter.AddSpecifiedRegion(1)

extract = vtkExtractUnstructuredGrid()
extract.SetInputConnection(connectivityFilter.GetOutputPort())
extract.CellClippingOn()
extract.SetCellMinimum(0)

‘’’
for the vtkSphereSource,
and
‘’’

创建一个连通性过滤器

connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
connectivityFilter.SetInputData(polydata)
connectivityFilter.SetExtractionModeToAllRegions()
connectivityFilter.ColorRegionsOn()
connectivityFilter.Update()

获取分块的数量

numberOfRegions = connectivityFilter.GetNumberOfExtractedRegions()
print(“Number of regions:”, numberOfRegions)

connectivityFilter.SetExtractionModeToSpecifiedRegions()
connectivityFilter.AddSpecifiedRegion(0)
‘’’
for the stl file.

when try to save it,
writer = vtk.vtkSTLWriter()
writer.SetFileName(“D:\Project\sw\VTK_learn\data\1_u_2_15_region_{}.stl”.format(0))
writer.SetInputData(connectivityFilter.GetOutputPort())
writer.Write()

there is an error:TypeError: SetInputData argument %Id: %V

I want to konw how to save the part,and how can I determine which function I should use?