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

**URL:** https://discourse.vtk.org/t/how-can-i-get-the-part-of-connectivityfilter-and-save-it-as-an-stl-file/12393
**Category:** Support
**Tags:** python, file-formats
**Created:** [September 30, 2023, 7:03am UTC](https://discourse.vtk.org/t/how-can-i-get-the-part-of-connectivityfilter-and-save-it-as-an-stl-file/12393 "2023-09-30T07:03:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![yangyang117](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/da6949/32.png) [@yangyang117](https://discourse.vtk.org/u/yangyang117)
#### Post date: [September 30, 2023, 7:03am UTC](https://discourse.vtk.org/t/how-can-i-get-the-part-of-connectivityfilter-and-save-it-as-an-stl-file/12393/1 "2023-09-30T07:03:30Z")

</div>

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?
