# How to write an STL or PLY in binary to bytes

**URL:** https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305
**Category:** Support
**Created:** [September 17, 2023, 11:27pm UTC](https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305 "2023-09-17T23:27:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JeffreyWardman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jeffreywardman/32/7717_2.png) [@JeffreyWardman](https://discourse.vtk.org/u/JeffreyWardman)
#### Post date: [September 17, 2023, 11:27pm UTC](https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305/1 "2023-09-17T23:27:22Z")

</div>

e.g. in Python, for both STLs and PLYs, I want to output a byte string rather than write directly to a file so I can use it in an API request.

E.g. something similar to vtk.vtkDataSetWriter()

```auto
writer = vtk.vtkSTLWriter()
writer.SetFileTypeToBinary()
writer.WriteToOutputStringOn()
writer.SetInputData(obj)
writer.GetBinaryOutputString()

```

---

<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: [September 18, 2023, 10:21am UTC](https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305/2 "2023-09-18T10:21:26Z")

</div>

HI @JeffreyWardman

vtkPLYWriter can write to output string:

[https://vtk.org/doc/nightly/html/classvtkPLYWriter.html#a4df553b07d920ff69d5a6677509fc2e9](https://vtk.org/doc/nightly/html/classvtkPLYWriter.html#a4df553b07d920ff69d5a6677509fc2e9)

---

<div class="post-metadata">

### Author: ![JeffreyWardman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jeffreywardman/32/7717_2.png) [@JeffreyWardman](https://discourse.vtk.org/u/JeffreyWardman)
#### Post date: [September 19, 2023, 1:13am UTC](https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305/3 "2023-09-19T01:13:30Z")

</div>

Thanks Mathieu. What about for STLs?

---

<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: [September 20, 2023, 6:38am UTC](https://discourse.vtk.org/t/how-to-write-an-stl-or-ply-in-binary-to-bytes/12305/4 "2023-09-20T06:38:12Z")

</div>

vtkSTLWriter does not support it sadly
