# How to export centerline model as .vtp files in slicer

**URL:** <https://discourse.slicer.org/t/how-to-export-centerline-model-as-vtp-files-in-slicer/40871>\
**Category:** VMTK\
**Tags:** python, vmtk-centerline\
**Created:** [December 27, 2024, 2:56pm UTC](https://discourse.slicer.org/t/how-to-export-centerline-model-as-vtp-files-in-slicer/40871 "2024-12-27T14:56:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pc666nice](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pc666nice/32/77252_2.png) [@pc666nice](https://discourse.slicer.org/u/pc666nice)\
**Post date:** [December 27, 2024, 2:56pm UTC](https://discourse.slicer.org/t/how-to-export-centerline-model-as-vtp-files-in-slicer/40871/1 "2024-12-27T14:56:46Z")

</div>

Dear all:  
I used the python code that has been proposed by [https://discourse.slicer.org/t/automatic-centerline/14829/23?u=pc666nice](https://here), but I can only generate the centerline curve, how I can generate centerline model and export as the vtp file. Here is my code:

```auto
segmentationName = 'MCA-2 1' # D:\PengChen\data-zhongshan\stlall1

segmentName = 'MCA-2 1'

segmentationNode = slicer.util.getNode(segmentationName)

segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)

extractLogic = ExtractCenterline.ExtractCenterlineLogic()

# Preprocess the surface 

inputSurfacePolyData = extractLogic.polyDataFromNode(segmentationNode, segmentID)

targetNumberOfPoints = 5000.0

decimationAggressiveness = 4 # I had to lower this to 3.5 in at least one case to get it to work, 4 is the default in the module

subdivideInputSurface = False

slicer.app.processEvents()

preprocessedPolyData = extractLogic.preprocess(inputSurfacePolyData, targetNumberOfPoints, decimationAggressiveness, subdivideInputSurface)

##############################################################

# Auto-detect the endpoints

endPointsMarkupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode", "Centerline endpoints")

networkPolyData = extractLogic.extractNetwork(preprocessedPolyData, endPointsMarkupsNode)

startPointPosition=None

endpointPositions = extractLogic.getEndPoints(networkPolyData, startPointPosition)

endPointsMarkupsNode.RemoveAllMarkups()

for position in endpointPositions:

endPointsMarkupsNode.AddControlPoint(vtk.vtkVector3d(position))

# Extract the centerline

centerlineCurveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode", "Centerline curve")

slicer.app.processEvents() # force update

# centerlinePolyData, voronoiDiagramPolyData = extractLogic.extractCenterline(preprocessedPolyData, endPointsMarkupsNode) ##################

centerlinePolyData, voronoiDiagramPolyData = extractLogic.extractCenterline(preprocessedPolyData, endPointsMarkupsNode, curveSamplingDistance=0.001) ##################

slicer.app.processEvents() # force update

centerlinePropertiesTableNode = None

extractLogic.createCurveTreeFromCenterline(centerlinePolyData, centerlineCurveNode, centerlinePropertiesTableNode)

```
