# Adding vtkPolyData as Source? \[solved\]

**URL:** https://discourse.paraview.org/t/adding-vtkpolydata-as-source-solved/9481
**Category:** ParaView Support
**Tags:** python
**Created:** [April 20, 2022, 6:07pm UTC](https://discourse.paraview.org/t/adding-vtkpolydata-as-source-solved/9481 "2022-04-20T18:07:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Devin\_Richard\_Bayly](https://discourse.paraview.org/user_avatar/discourse.paraview.org/devin_richard_bayly/32/5533_2.png) [@Devin\_Richard\_Bayly](https://discourse.paraview.org/u/Devin_Richard_Bayly)
#### Post date: [April 20, 2022, 6:07pm UTC](https://discourse.paraview.org/t/adding-vtkpolydata-as-source-solved/9481/1 "2022-04-20T18:07:59Z")

</div>

Hi there,  
**Wait seems like TrivialProducer is what I’m looking for**  
I’m just getting started with Paraview and was hoping to experiment with generating polydata programmatically to view in Paraview just to get some shapes to work with that I can mess around with. I stumbled on the Live Programmable Source and an article showing how to create things with it in the GUI ([https://cvw.cac.cornell.edu/ParaViewAdv/progsource](https://cvw.cac.cornell.edu/ParaViewAdv/progsource)). I was wondering if there’s a way to write the following in the paraview python shell instead of Programmable Live Source and have a render of it appear in the View.

```auto
import paraview.vtk as vtk

points = vtk.vtkPoints()
points.InsertPoint(0, 0, 0, 0)
points.InsertPoint(1, 1, 0, 0)
points.InsertPoint(2, 0, 1, 0)
points.InsertPoint(3, 0, 0, 1)
pdo = vtk.vtkPolyData()
triangle = vtk.vtkPolygon()
triangle.GetPointIds().SetNumberOfIds(3)

tris = [[0,1,2], [0,2,3], [0,3,1], [1,3,2]]
for t in range(0, 4):
    for p in range(0, 3):
        triangle.GetPointIds().SetId(p, tris[t][p])
    pdo.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds())

```

I’ve tried to run `Show()` or `Render()` after all this but I suppose since I don’t have a source representing the polydata there’s no reason to believe those would have worked. Thanks for anyone who can suggest how I would make this `pdo` variable visible.

---

<div class="post-metadata">

### Author: ![Devin\_Richard\_Bayly](https://discourse.paraview.org/user_avatar/discourse.paraview.org/devin_richard_bayly/32/5533_2.png) [@Devin\_Richard\_Bayly](https://discourse.paraview.org/u/Devin_Richard_Bayly)
#### Post date: [April 20, 2022, 6:22pm UTC](https://discourse.paraview.org/t/adding-vtkpolydata-as-source-solved/9481/2 "2022-04-20T18:22:48Z")

</div>

Like I mentioned in the top of the original post, it looks like I need the `TrivialProducer` but there’s a new issue that something in the script is causing a seg fault when it tries to insert the tris as cells. I might make a new issue out of this shortly, but I figure I should post here that the code above might be buggy.

---

<div class="post-metadata">

### Author: ![Devin\_Richard\_Bayly](https://discourse.paraview.org/user_avatar/discourse.paraview.org/devin_richard_bayly/32/5533_2.png) [@Devin\_Richard\_Bayly](https://discourse.paraview.org/u/Devin_Richard_Bayly)
#### Post date: [April 20, 2022, 6:32pm UTC](https://discourse.paraview.org/t/adding-vtkpolydata-as-source-solved/9481/3 "2022-04-20T18:32:41Z")

</div>

When running from pvpython this seems to have worked for my purposes.

```auto
import paraview.vtk as vtk
from paraview.simple import *

points = vtk.vtkPoints()
points.InsertPoint(0, 0, 0, 0)
points.InsertPoint(1, 1, 0, 0)
points.InsertPoint(2, 0, 1, 0)
points.InsertPoint(3, 0, 0, 1)
pdo = vtk.vtkPolyData()
pdo.SetPoints(points)
pdo.Allocate(4, 4)

triangle = vtk.vtkPolygon()
triangle.GetPointIds().SetNumberOfIds(3)

tris = [[0,1,2], [0,2,3], [0,3,1], [1,3,2]]
for t in range(0, 4):
    for p in range(0, 3):
        triangle.GetPointIds().SetId(p, tris[t][p])
    pdo.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds())

tp = TrivialProducer()
tp = TrivialProducer()
tp.GetClientSideObject().SetOutput(pdo)
Show(tp)
Render()
Interact()

```
