# How can I export Tubes to .obj

**URL:** https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015
**Category:** Support
**Created:** [June 17, 2021, 10:57pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015 "2021-06-17T22:57:22Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 17, 2021, 10:57pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/1 "2021-06-17T22:57:22Z")

</div>

Hi,

I am wondering how to export tubes to a .obj file. I am trying to visualize Networkx graphs with vtk and create a model, but the vtkOBJExporter() will not export the tubes. I have tried turning capping on but that did not yield any results. I have written my snippet of code that builds the tubes below. Thanks.

lines = vtk.vtkCellArray()  
i=0  
for e in G.edges:

```
    u=e[0] 
    v=e[1] 

    lines.InsertNextCell(2) 

    for n in (u,v): 
        (x,y,z)=node_pos[n] 
        points.InsertPoint(i, x, y, z) 
        lines.InsertCellPoint(i) 
        i=i+1 

edgeData.SetPoints(points) 
edgeData.SetLines(lines) 

Tubes = vtk.vtkTubeFilter() 
Tubes.SetNumberOfSides(16) 
Tubes.SetCapping(True)
Tubes.SetInputData(edgeData) 
Tubes.SetRadius(0.01) # edge RADIUS 
Tubes.CappingOn()
```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 19, 2021, 9:59pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/2 "2021-06-19T21:59:53Z")

</div>

Hi, Matt,

Is that your entire code? You know, `vtkExport` (and its subclasses) exports a scene. If you’re not creating `vtkActor`s, etc. it indeed won’t export the tubes.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 19, 2021, 11:55pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/3 "2021-06-19T23:55:59Z")

</div>

That is not my entire code my apologies. I created a vtkActor for the tubes however they are still not being exported. Thanks for the response. Below is my entire code.

```
# set node positions 
np={} 
for n in G.nodes():

    np[n]=node_pos[n] 

nodePoints = vtk.vtkPoints() 

i=0 

for (x,y,z) in np.values(): 
    nodePoints.InsertPoint(i, x, y, z) 
    i=i+1 

# Create a polydata to be glyphed. 
inputData = vtk.vtkPolyData() 
inputData.SetPoints(nodePoints) 

# Use sphere as glyph source. 
balls = vtk.vtkSphereSource() 
balls.SetRadius(.1) 
balls.SetPhiResolution(20) 
balls.SetThetaResolution(20) 

glyphPoints = vtk.vtkGlyph3D() 
glyphPoints.SetInputData(inputData) 
glyphPoints.SetSourceData(balls.GetOutput()) 

glyphMapper = vtk.vtkPolyDataMapper() 
glyphMapper.SetInputData(glyphPoints.GetOutput()) 

glyph = vtk.vtkActor() 
glyph.SetMapper(glyphMapper) 
glyph.GetProperty().SetDiffuseColor(plum) 
glyph.GetProperty().SetSpecular(.3) 
glyph.GetProperty().SetSpecularPower(30) 

# Generate the polyline for the spline. 
points = vtk.vtkPoints() 
edgeData = vtk.vtkPolyData() 

# Edges 

lines = vtk.vtkCellArray() 
i=0 
for e in G.edges: 

    u=e[0] 
    v=e[1] 

    lines.InsertNextCell(2) 

    for n in (u,v): 
        (x,y,z)=node_pos[n] 
        points.InsertPoint(i, x, y, z) 
        lines.InsertCellPoint(i) 
        i=i+1 

edgeData.SetPoints(points) 
edgeData.SetLines(lines) 

Tubes = vtk.vtkTubeFilter() 
Tubes.CappingOn()
Tubes.SetNumberOfSides(16) 
Tubes.SetInputData(edgeData) 
Tubes.SetRadius(0.06) # edge RADIUS 
Tubes.Update()  

profileMapper = vtk.vtkPolyDataMapper() 
profileMapper.SetInputData(Tubes.GetOutput()) 

profile = vtk.vtkActor() 
profile.SetMapper(profileMapper) 
profile.GetProperty().SetDiffuseColor(banana) 
profile.GetProperty().SetSpecular(.3) 
profile.GetProperty().SetSpecularPower(30) 

balls.Update()

glyphPoints.Update()    

ren = vtk.vtkRenderer() 
renWin = vtk.vtkRenderWindow() 
renWin.AddRenderer(ren) 

iren = vtk.vtkRenderWindowInteractor() 
iren.SetRenderWindow(renWin) 

ren.AddActor(profile)
ren.AddActor(glyph) 
 

renWin.SetSize(1000, 1000) 

iren.Initialize() 
renWin.Render() 

iren.Start()     

writer = vtk.vtkOBJExporter()
writer.SetFilePrefix('test3')
writer.SetInput(renWin)
writer.Write()
```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 20, 2021, 2:27pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/4 "2021-06-20T14:27:10Z")

</div>

Do you see the tubes in the render window?

---

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 20, 2021, 2:36pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/5 "2021-06-20T14:36:43Z")

</div>

Yes they render perfectly. However when I open the .obj file in Meshlab there are no tubes just the balls.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 20, 2021, 8:59pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/6 "2021-06-20T20:59:24Z")

</div>

Try moving `Tubes.Update()` to where `balls.Update()` and `glyphPoints.Update()` are. Maybe the file writer requires that the algorithms be executed after their outputs are connected to their respective `vtkActor`s.

---

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 20, 2021, 9:36pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/7 "2021-06-20T21:36:08Z")

</div>

Nothing changed after moving it unfortunately. Still renders it perfectly, however after exporting and opening the .obj file in Meshlab there are still no tubes. Thanks for the help by the way!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 20, 2021, 10:05pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/8 "2021-06-20T22:05:51Z")

</div>

Well, maybe that is a bug. You can report it here: [https://gitlab.kitware.com/vtk/vtk/-/issues](https://gitlab.kitware.com/vtk/vtk/-/issues) . If it is not a bug you’ll get a feedback of what you might be doing wrong. Since your code is stand-alone, I think you have a good chance to have it solved. Don’t forget to include everything (e.g. `import`s, input data, etc.).

---

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 20, 2021, 10:08pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/9 "2021-06-20T22:08:05Z")

</div>

Thankyou !

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 20, 2021, 10:10pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/10 "2021-06-20T22:10:50Z")

</div>

You’re welcome! But I can’t further help you, since I work with C++. I don’t even have a Python environment set up. Sorry.

Please, can you be so kind as to post the link to the bug report here if you decide to do so? Thanks.

---

<div class="post-metadata">

### Author: ![Matt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matt/32/3574_2.png) [@Matt](https://discourse.vtk.org/u/Matt)
#### Post date: [June 20, 2021, 10:25pm UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/11 "2021-06-20T22:25:43Z")

</div>

[https://gitlab.kitware.com/vtk/vtk/-/issues/18241](https://gitlab.kitware.com/vtk/vtk/-/issues/18241)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [June 23, 2021, 7:59am UTC](https://discourse.vtk.org/t/how-can-i-export-tubes-to-obj/6015/12 "2021-06-23T07:59:13Z")

</div>

Your script has many issues, in any case here is an example on how to use the vtkObjExporter with tubes:  
[test.py](https://discourse.vtk.org/uploads/short-url/5yrk77pwgmFBDi4WRgi6RXdSpHW.py) (771 Bytes)

So, not a VTK issue.
