# Exporting a model to STL with markups

**URL:** <https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502>\
**Category:** Support\
**Created:** [November 30, 2022, 4:36am UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502 "2022-11-30T04:36:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bremsstrahlung](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bremsstrahlung/32/16851_2.png) [@bremsstrahlung](https://discourse.slicer.org/u/bremsstrahlung)\
**Post date:** [November 30, 2022, 4:36am UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/1 "2022-11-30T04:36:22Z")

</div>

I have a model and have a point list of markups on the model, How do i export this model to STL with the control points?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 30, 2022, 2:07pm UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/2 "2022-11-30T14:07:15Z")

</div>

You could use a Python snippet like this

```auto
fiducialNode = getNode('F')
import numpy as np
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(1)
for i in range(fiducialNode.GetNumberOfControlPoints()):
  p = np.zeros(3)
  fiducialNode.GetNthControlPointPosition(i, p)
  fiducialModel = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode', f'Model_{fiducialNode.GetName()}_{i}')
  sphereSource.SetCenter(p)
  polyData = vtk.vtkPolyData()
  sphereSource.Update()
  polyData.DeepCopy(sphereSource.GetOutput())
  fiducialModel.SetAndObservePolyData(polyData)

```

Please note you’ll need to replace the name of your fiducial node (in my example it is `F`) and set the sphere radius as desired.

Once you have the model nodes you can append them together in Dynamic Modeler module’s Append feature, then export to STL.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 1, 2022, 2:12am UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/3 "2022-12-01T02:12:08Z")

</div>

Alternatively, you can use a glyph filter like this:

```python
markup = getNode('F')
glyph = vtk.vtkSphereSource()
glyph.SetRadius(15.0)
glypher = vtk.vtkGlyph3D()
glypher.SetSourceConnection(glyph.GetOutputPort())
glypher.SetInputConnection(markup.GetCurveWorldConnection())
model = slicer.modules.models.logic().AddModel(glypher.GetOutputPort())
slicer.util.saveNode(model, "c:/tmp/something.stl")

```

---

<div class="post-metadata">

**Author:** ![bremsstrahlung](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bremsstrahlung/32/16851_2.png) [@bremsstrahlung](https://discourse.slicer.org/u/bremsstrahlung)\
**Post date:** [December 2, 2022, 4:08am UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/4 "2022-12-02T04:08:17Z")

</div>

Both of the above mentioned solutions work perfectly, i can now export a model that has all the points on it. Thank You.  
Would it be possible to have the points and the model to be in different colors? When i use the Append feature in Dynamic Modeler the final Model is of all the same color, i would prefer if the points and my model where of different colours.

---

<div class="post-metadata">

**Author:** ![bremsstrahlung](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bremsstrahlung/32/16851_2.png) [@bremsstrahlung](https://discourse.slicer.org/u/bremsstrahlung)\
**Post date:** [December 2, 2022, 5:49am UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/5 "2022-12-02T05:49:33Z")

</div>

Can this be extended to a curve? If my markups are in the form of a curve, can that be exported to an STL?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 2, 2022, 3:15pm UTC](https://discourse.slicer.org/t/exporting-a-model-to-stl-with-markups/26502/6 "2022-12-02T15:15:16Z")

</div>

Yes, it works exactly the same way for curves, just replace the glyph filter by tube filter.
