# How to export model node to VRML 2 and STL (ascii and binary)

**URL:** <https://discourse.slicer.org/t/how-to-export-model-node-to-vrml-2-and-stl-ascii-and-binary/10804>\
**Category:** Development\
**Created:** [March 23, 2020, 7:35pm UTC](https://discourse.slicer.org/t/how-to-export-model-node-to-vrml-2-and-stl-ascii-and-binary/10804 "2020-03-23T19:35:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjg](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mjg](https://discourse.slicer.org/u/mjg)\
**Post date:** [March 23, 2020, 7:35pm UTC](https://discourse.slicer.org/t/how-to-export-model-node-to-vrml-2-and-stl-ascii-and-binary/10804/1 "2020-03-23T19:35:37Z")

</div>

Hello,

I need to be able to export a model node as VRML 2, ascii STL, and binary STL files for a module I am developing. I know essentially nothing about vtk so any help or resources you could provide would be lovely.

Thank you!

---

<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:** [March 23, 2020, 7:51pm UTC](https://discourse.slicer.org/t/how-to-export-model-node-to-vrml-2-and-stl-ascii-and-binary/10804/2 "2020-03-23T19:51:42Z")

</div>

The easiest to export to binary STL and OBJ is to use this [ExportSegmentsClosedSurfaceRepresentationToFiles](http://apidocs.slicer.org/master/classvtkSlicerSegmentationsModuleLogic.html#a4b5328985b2d98cbbc93a5b2ae7fde6b) method.

VRML is really really old, I would not recommend to use it, but fortunately VTK still supports it. VTK also has ASCII option for writing STL. You can do the export in two steps:

1. Export segmentation to model - [se example here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Export_model_nodes_from_segmentation_node)
2. Get vtkPolyData from the created model nodes and use [vtkSTLWriter](https://vtk.org/doc/nightly/html/classvtkSTLWriter.html) and [vtkVRMLExporter](https://vtk.org/doc/nightly/html/classvtkVRMLExporter.html). See examples for getting vtkPolyData from a model node and write to file in [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository); a complete example of using an exporter in [this module](https://github.com/PerkLab/SlicerOpenAnatomy/blob/master/OpenAnatomyExport/OpenAnatomyExport.py).

---

<div class="post-metadata">

**Author:** ![mjg](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mjg](https://discourse.slicer.org/u/mjg)\
**Post date:** [March 23, 2020, 9:18pm UTC](https://discourse.slicer.org/t/how-to-export-model-node-to-vrml-2-and-stl-ascii-and-binary/10804/3 "2020-03-23T21:18:37Z")

</div>

Perfect, I got it working. Thank you so much!
