<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi guys,<br>
<br>
I hope this has not been already asked but the archives are not
really handy to explore...<br>
<br>
I'm converting stl files from ascii to binary and from binary to
ascii with vtk. I use the following code:<br>
<br>
#!/usr/bin/env python<br>
<br>
import vtk<br>
<br>
<br>
def convert_stl2ascii(path):<br>
reader = vtk.vtkSTLReader()<br>
<br>
reader.SetFileName(path)<br>
reader.Update()<br>
write = vtk.vtkSTLWriter()<br>
write.SetFileTypeToASCII()<br>
<br>
write.SetInput(reader.GetOutput())<br>
write.SetFileName(path)<br>
write.Write()<br>
<br>
<br>
def convert_stl2binary(path):<br>
reader = vtk.vtkSTLReader()<br>
<br>
reader.SetFileName(path)<br>
reader.Update()<br>
write = vtk.vtkSTLWriter()<br>
write.SetFileTypeToBinary()<br>
<br>
write.SetFileName('_binary.stl'.join(path.split('.stl')))<br>
write.SetInput(reader.GetOutput())<br>
write.Write()<br>
<br>
<br>
<br>
It does work BUT, Let's say I have a ascii stl file like this:
<pre class="lang-py prettyprint prettyprinted" style="margin: 0px 0px 10px; padding: 5px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; word-wrap: normal; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.80480194091797px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(238, 238, 238);"><code style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; backg
round: rgb(238, 238, 238);"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">solid first_name
</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">[...]</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">
endsolid
solid second_name
</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">[...]</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">
endsolid</span></code></pre>
<p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size:
13.333333969116211px; vertical-align: baseline; clear: both;
color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans',
'DejaVu Sans', sans-serif; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal; line-height:
17.80480194091797px; orphans: auto; text-align: left; text-indent:
0px; text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px; background:
rgb(255, 255, 255);">I can convert it to a binary file but when I
try to convert it back to ascii, I get something like:</p>
<pre class="lang-py prettyprint prettyprinted" style="margin: 0px 0px 10px; padding: 5px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; word-wrap: normal; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.80480194091797px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(238, 238, 238);"><code style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; backg
round: rgb(238, 238, 238);"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">solid ascii
</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">[...]</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.333333969116211px; vertical-align: baseline; color: rgb(0, 0, 0); background: transparent;">
endsolid</span></code></pre>
<p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size:
13.333333969116211px; vertical-align: baseline; clear: both;
color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans',
'DejaVu Sans', sans-serif; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal; line-height:
17.80480194091797px; orphans: auto; text-align: left; text-indent:
0px; text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px; background:
rgb(255, 255, 255);">What should I do to keep the Region name
first_name and second_name and to avoid that several different
regions to be merged in only one region?</p>
<p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size:
13.333333969116211px; vertical-align: baseline; clear: both;
color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans',
'DejaVu Sans', sans-serif; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal; line-height:
17.80480194091797px; orphans: auto; text-align: left; text-indent:
0px; text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px; background:
rgb(255, 255, 255);">Cheers !!</p>
</body>
</html>