STL importer ValueError exception #34682

Closed
opened 2013-03-18 21:54:25 +01:00 by Florian Lindner · 3 comments

%%%Importing an STL file 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

  for _ in range(3)]

ValueError: could not convert string to float: b'loop'

STL file fragment that produces the crash is attached, or simple take:

solid Solid

 color       0.81961 0.18824 0.42353
facet normal 0.288935958 0.957348417 -0.000142096066
  outer loop
    vertex 681.368134 2.98766105 520.700039
    vertex 683.077134 2.4718702 520.700027
    vertex 681.368674 2.98636304 513.052942
  endloop
endfacet

endsolid Solid

First investigatios at 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 Solid

  • 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 Solid"
  while True:
    # strip facet normal // or end
      data.readline()  # strips color not facet, so it's one line off
    - strip outer loup, in case of ending, break the loop
    - Here is strips "facet..."
      if not data.readline():
          break
   # Crashes because it tried to convert "outer" to float
      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 at the last line
which makes the loop crash at this 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).

- Operating System, Graphics card ---

Arch Linux

- Blender version with error, and version that worked ---

Blender 2.66a / 2.66.1
%%%

%%%Importing an STL file 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' STL file fragment that produces the crash is attached, or simple take: solid Solid ``` color 0.81961 0.18824 0.42353 facet normal 0.288935958 0.957348417 -0.000142096066 outer loop vertex 681.368134 2.98766105 520.700039 vertex 683.077134 2.4718702 520.700027 vertex 681.368674 2.98636304 513.052942 endloop endfacet ``` endsolid Solid First investigatios at 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 Solid - 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 Solid" ``` ``` while True: ``` # strip facet normal // or end ``` data.readline() # strips color not facet, so it's one line off ``` - strip outer loup, in case of ending, break the loop - Here is strips "facet..." ``` if not data.readline(): break ``` # Crashes because it tried to convert "outer" to float ``` 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 at the last line which makes the loop crash at this 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). - Operating System, Graphics card --- Arch Linux - Blender version with error, and version that worked --- Blender 2.66a / 2.66.1 %%%

Changed status to: 'Open'

Changed status to: 'Open'

%%%fix r4429 of the extensions repo.%%%

%%%fix r4429 of the extensions repo.%%%

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#34682
No description provided.