# Simple example to add a vtk object to Slicer 3D view

**URL:** <https://discourse.slicer.org/t/simple-example-to-add-a-vtk-object-to-slicer-3d-view/4797>\
**Category:** Support\
**Created:** [November 19, 2018, 10:54am UTC](https://discourse.slicer.org/t/simple-example-to-add-a-vtk-object-to-slicer-3d-view/4797 "2018-11-19T10:54:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [November 19, 2018, 10:54am UTC](https://discourse.slicer.org/t/simple-example-to-add-a-vtk-object-to-slicer-3d-view/4797/1 "2018-11-19T10:54:18Z")

</div>

Operating system: Ubuntu 18.04  
Slicer version: 4.10

This is not a question but a simple example for beginners. The sphere can be replaced by other polydata object.

```
 import vtk
 source = vtk.vtkSphereSource()
 source.SetRadius(50.0)
 source.SetCenter(0,0,0)
 source.Update() 
 pd = source.GetOutput() # a polydat aobject
 slicer.modules.models.logic().AddModel(pd)
```

---

<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:** [November 19, 2018, 1:32pm UTC](https://discourse.slicer.org/t/simple-example-to-add-a-vtk-object-to-slicer-3d-view/4797/2 "2018-11-19T13:32:31Z")

</div>

Thanks for taking the time to share this. We maintain a list of code snippets in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository). It would be great if you could add it there.

I also have a suggestion for possible simplification of the code, using the source’s output port:

```auto
import vtk
source = vtk.vtkSphereSource()
source.SetRadius(50.0)
source.SetCenter(0,0,0)
modelNode = slicer.modules.models.logic().AddModel(source.GetOutputPort())

```
