[Bf-committers] Crash on STL import

Florian Lindner mailinglists at xgm.de
Sun Mar 17 11:42:13 CET 2013


Hello,

Blender 2.66.1 on Arch Linux.

When I try to import an STL it gives the following traceback:

Traceback (most recent call last):
  File "/usr/share/blender/2.66/scripts/addons/io_mesh_stl/__init__.py", line 
104, in execute
    tris, pts = stl_utils.read_stl(path)
  File "/usr/share/blender/2.66/scripts/addons/io_mesh_stl/stl_utils.py", line 
249, in read_stl
    for pt in gen(data):
  File "/usr/share/blender/2.66/scripts/addons/io_mesh_stl/stl_utils.py", line 
156, in _ascii_read
    for _ in range(3)]
  File "/usr/share/blender/2.66/scripts/addons/io_mesh_stl/stl_utils.py", line 
156, in <listcomp>
    for _ in range(3)]
ValueError: could not convert string to float: b'loop'


Having a little look at the source stl_utils.py

def _ascii_read(data):
    # an stl ascii file is like
    # HEADER: solid some name
    # for each face:
    #
    #     facet normal x y z
    #     outerloop
    #          vertex x y z
    #          vertex x y z
    #          vertex x y z
    #     endloop
    #     endfacet

   # My STL differs, it's:
   # solid GEOM_sol_InnerTopSting
   # color      R G B 
   # facet normal 0.288935958 0.957348417 -0.000142096066
   # outer loop
   #          vertex x y z
   #          vertex x y z
   #          vertex x y z
   # endloop
   # endfacet

  # I have a an additional color line in the header and mit loop is initated
  # by outer loop (which does not matter with the code)

    # strip header
    data.readline()  #  strips solid GEOM....

    while True:
        # strip facet normal // or end
        data.readline()  # strips color, so it's on line off

        # strip outer loup, in case of ending, break the loop
        if not data.readline():
            break

       # Crashes
        yield [tuple(map(float, data.readline().split()[1:]))
               for _ in range(3)]

        # strip facet normalend and outerloop end
        data.readline()
        data.readline()


Adding another data.readline() at the top to strip the color header makes the 
loop run fine till the end. My STL has a trailing newline hat the last line 
which makes the loop chrash there now.

The STLs are generated by ANSA or CATIA and accepted from Paraview, Numeca 
Spider or OpenFOAM's snappyHexMesh. (these STLs are input geometries for CFD 
calculations).

Regards,
Florian


More information about the Bf-committers mailing list