[vtkusers] Some Help for a vtk beginner!

David Gobbi david.gobbi at gmail.com
Fri May 30 13:26:38 EDT 2014


Hi Adrien,

This is the first time that I've heard this question.  The answer is that the
vtkSTLWriter is not sophisticated enough to write files with multiple solids.
This is a bit strange, because the vtkSTLReader is capable of labeling the
solids when it reads them.

  David


On Fri, May 30, 2014 at 11:06 AM, Adrien Brunet <brunet.adrien at gmail.com> wrote:
> Hi guys,
>
> I hope this has not been already asked but the archives are not really handy
> to explore...
>
> I'm converting stl files from ascii to binary and from binary to ascii with
> vtk. I use the following code:
>
> #!/usr/bin/env python
>
> import vtk
>
>
> def convert_stl2ascii(path):
>     reader = vtk.vtkSTLReader()
>
>     reader.SetFileName(path)
>     reader.Update()
>     write = vtk.vtkSTLWriter()
>     write.SetFileTypeToASCII()
>
>     write.SetInput(reader.GetOutput())
>     write.SetFileName(path)
>     write.Write()
>
>
> def convert_stl2binary(path):
>     reader = vtk.vtkSTLReader()
>
>     reader.SetFileName(path)
>     reader.Update()
>     write = vtk.vtkSTLWriter()
>     write.SetFileTypeToBinary()
>
>     write.SetFileName('_binary.stl'.join(path.split('.stl')))
>     write.SetInput(reader.GetOutput())
>     write.Write()
>
>
>
> It does work BUT, Let's say I have a ascii stl file like this:
>
> solid first_name
>     [...]
> endsolid
> solid second_name
>     [...]
> endsolid
>
> I can convert it to a binary file but when I try to convert it back to
> ascii, I get something like:
>
> solid ascii
>     [...]
> endsolid
>
> 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?
>
> Cheers !!


More information about the vtkusers mailing list