# How can I use the module of "Markups to Model" in command line?

**URL:** https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722
**Category:** Support
**Created:** [August 10, 2018, 2:44pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722 "2018-08-10T14:44:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)
#### Post date: [August 10, 2018, 2:44pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/1 "2018-08-10T14:44:24Z")

</div>

Hi  
Dear developers and users

How can I use the module of “Markups to Model” in command line?  
I noticed that I can create a tube model around of centerline using the module of “Markups to Model” . At now, I want create this tube using this module in the command line. How can I do it?  
Is it another module to create the tube around centerline?

Please guide me.  
Shahrokh

---

<div class="post-metadata">

### Author: ![tavaughan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tavaughan/32/1475_2.png) [@tavaughan](https://discourse.slicer.org/u/tavaughan)
#### Post date: [August 10, 2018, 3:24pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/2 "2018-08-10T15:24:04Z")

</div>

Hi shahrokh,

You mean through python interactor?

There is no public function in the module yet to do this, but I can add one. In the meantime you can use vtk.vtkTubeFilter ([https://www.vtk.org/doc/nightly/html/classvtkTubeFilter.html](https://www.vtk.org/doc/nightly/html/classvtkTubeFilter.html)) to create tube poly data around the points. Something like this (note I haven’t personally tried running this so you may need to tweak it):

```auto
  numPoints = pointsToConnect.GetNumberOfPoints()
  lineCellArray = vtk.vtkCellArray()
  lineCellArray.InsertNextCell( numPoints )

  for i in xrange(0,numPoints)
  {
    lineCellArray.InsertCellPoint( i )
  }

  linePolyData = vtk.vtkPolyData()
  linePolyData.SetPoints( pointsToConnect )
  linePolyData.SetLines( lineCellArray )

  tubeSegmentFilter = vtk.vtkTubeFilter()
  tubeSegmentFilter.SetInputData( linePolyData )
  tubeSegmentFilter.SetRadius( tubeRadius ) #INSERT VALUE
  tubeSegmentFilter.SetNumberOfSides( tubeNumberOfSides ) #INSERT VALUE
  tubeSegmentFilter.CappingOn()
  tubeSegmentFilter.Update()

  # Access poly data by calling tubeSegmentFilter.GetOutput()

```

If you want to assign it to a vtkMRMLModelNode you’ll need to do:

```auto
  modelNode.SetAndObservePolyData( tubeSegmentFilter.GetOutput() )
  modelNode.CreateDefaultDisplayNodes()

```

I hope that helps. If it doesn’t answer your question please let me know.

Thomas

---

<div class="post-metadata">

### Author: ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)
#### Post date: [August 13, 2018, 2:26pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/3 "2018-08-13T14:26:24Z")

</div>

Hello  
Dear Thomas,

Thanks a lot for your guidance. At now, I want to create tube poly data around the points in my vtp centerline file according with your commands.  
I have some problems to do it.  
I enter the following commands in python interactor of Slicer.

import vtk  
filename = “~/centerlineRodCT001.vtp”  
reader = vtk.vtkXMLPolyDataReader()  
reader.SetFileName(filename)  
reader.Update()  
numPoints = reader.GetNumberOfPoints()  
lineCellArray = vtk.vtkCellArray()  
lineCellArray.InsertNextCell(numPoints)  
for i in range(0,numPoints):  
lineCellArray.InsertCellPoint( i )  
linePolyData = vtk.vtkPolyData()  
linePolyData.SetPoints(reader)

At this moment, I get the following error.  
Traceback (most recent call last):  
File “”, line 1, in   
TypeError: SetPoints argument 1: method requires a vtkPoints, a vtkXMLPolyDataReader was provided.

Please guide me. How can I get vtkPoints argument?  
Best regards,  
Shahrokh

---

<div class="post-metadata">

### Author: ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)
#### Post date: [August 14, 2018, 2:17pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/4 "2018-08-14T14:17:28Z")

</div>

Excuse me. Unfortunately I can not find any python code example about reading centelines vtp file and applying vtktubefilter to it. Please let me know where I wrong it.  
Thanks a lot.  
Shahrokh

---

<div class="post-metadata">

### Author: ![tavaughan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tavaughan/32/1475_2.png) [@tavaughan](https://discourse.slicer.org/u/tavaughan)
#### Post date: [August 14, 2018, 5:01pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/5 "2018-08-14T17:01:14Z")

</div>

Assuming that the points saved in the file are already in the correct order…

This should get you a vtkPolyData object:  
polydata = reader.GetOutput()

This should get you a vtkPoints object from the vtkPolyData object:  
points = polydata.GetPoints()

---

<div class="post-metadata">

### Author: ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)
#### Post date: [August 14, 2018, 5:23pm UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/6 "2018-08-14T17:23:28Z")

</div>

Dear Thomas  
Thanks a lot for your guidance. I’m sure this solves my problem.  
Best regards.

---

<div class="post-metadata">

### Author: ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)
#### Post date: [August 15, 2018, 9:15am UTC](https://discourse.slicer.org/t/how-can-i-use-the-module-of-markups-to-model-in-command-line/3722/7 "2018-08-15T09:15:33Z")

</div>

Dear Thomas

Thanks a lot for your guidance. Finally, I can create a tube around the centerline vtp file with the following lines:

import vtk

filename = “/home/sn/centerlineRodCT001.vtp”  
reader = vtk.vtkXMLPolyDataReader()  
reader.SetFileName(filename)  
reader.Update()  
polydata = reader.GetOutput()  
points = polydata.GetPoints()  
numPoints = reader.GetNumberOfPoints()  
lineCellArray = vtk.vtkCellArray()  
lineCellArray.InsertNextCell(numPoints)  
for i in range(0,numPoints):  
lineCellArray.InsertCellPoint( i )  
linePolyData = vtk.vtkPolyData()  
linePolyData.SetPoints(points)  
linePolyData.SetLines( lineCellArray )  
tubeSegmentFilter = vtk.vtkTubeFilter()  
tubeSegmentFilter.SetInputData( linePolyData )  
tubeSegmentFilter.SetRadius(2)  
tubeSegmentFilter.SetNumberOfSides(10)  
tubeSegmentFilter.SetOutputPointsPrecision(1)  
tubeSegmentFilter.CappingOn()  
tubeSegmentFilter.Update()  
tubeSegmentFilter.GetOutput()  
writer = vtk.vtkXMLPolyDataWriter()  
writer.SetFileName(“tube.vtp”)  
writer.SetInputDataObject(tubeSegmentFilter.GetOutput())  
writer.Write()

Best regards,  
Shahrokh
