Menu

Error importing STL files from blender

Help
Sliptonic
2008-12-08
2013-03-08
  • Sliptonic

    Sliptonic - 2008-12-08

    I've managed to get pycam running on Ubuntu Hardy.  It seems to work with the included sample STL files.  However, when I try to open a model exported from blender, I get the following error:

    Traceback (most recent call last):
      File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1406, in __call__
        return self.func(*args)
      File "/home/bob/emc2/nc_files/pycam-0.1.5/pycam/Gui/SimpleGui.py", line 156, in browseOpen
        self.scale = 2.0/self.model.maxsize()
      File "/home/bob/emc2/nc_files/pycam-0.1.5/pycam/Geometry/Model.py", line 85, in maxsize
        self._maxsize = max3(max(abs(self.maxx),abs(self.minx)),max(abs(self.maxy),abs(self.miny)),max(abs(self.maxz),abs(self.minz)))
    AttributeError: Model instance has no attribute 'maxx'

    Blender is able to import the sample STL files as well.

    Google has nothing on the error so I'm posting back here.  Any guidance is appreciated.

     
    • Lode Leroy

      Lode Leroy - 2008-12-08

      could you post a small STL file that illustrates the error? I do not have blender, so I cannot try it out..

      -- lode

       
      • Sliptonic

        Sliptonic - 2008-12-08

        Trying to comply with your request I might have found the issue.   Sorry but I'm an STL noob.  I didn't realize the format had both an ascii and binary version.  Blender exports only the binary version and I assume pycam reads only the ascii.

        Blender is GPL software freely available from blender.org and I'm just trying to export the default cube.  I'll upload the binary STL if it's useful but I don't see how to attach binaries to this forum.

         
    • Lode Leroy

      Lode Leroy - 2008-12-09

      Indeed, pycam only reads the ASCII variant for now.

      -- lode

       
    • Daniel Patterson

      Here's a python script to convert from binary STL to ascii format.  I use it to convert Blender files into STL files that pycam can load up:

      ---------------------------------------------------------------------
      #!/usr/bin/python

      from struct import unpack

      f = open("stock.stl","rb")

      header = f.read(80)
      numfacets = unpack("<I",f.read(4))[0]

      print "solid stock"

      for i in range(1,numfacets):
        a1 = unpack("<f",f.read(4))[0]
        a2 = unpack("<f",f.read(4))[0]
        a3 = unpack("<f",f.read(4))[0]

        v11 = unpack("<f",f.read(4))[0]
        v12 = unpack("<f",f.read(4))[0]
        v13 = unpack("<f",f.read(4))[0]

        v21 = unpack("<f",f.read(4))[0]
        v22 = unpack("<f",f.read(4))[0]
        v23 = unpack("<f",f.read(4))[0]

        v31 = unpack("<f",f.read(4))[0]
        v32 = unpack("<f",f.read(4))[0]
        v33 = unpack("<f",f.read(4))[0]

        attribs = unpack("<H",f.read(2))

        print "facet normal %f %f %f" % (a1, a2, a3)
        print "  outer loop"
        print "    vertex %f %f %f" % (v11, v12, v13)
        print "    vertex %f %f %f" % (v21, v22, v33)
        print "    vertex %f %f %f" % (v31, v32, v33)
        print "  endloop"
        print "endfacet"

       
      print "endsolid stock"

       
      • Lode Leroy

        Lode Leroy - 2009-07-13

        Thanks. I integrated this into pycam.

         
  • Sliptonic

    Sliptonic - 2010-03-14

    lode_leroy, Thanks for implementing the conversion script above but I'm having trouble making it go.

    I'm using blender 2.45 and pycam 0.2.1 (or svn).  When I try to load an stl exported from blender, pycam thinks for a second and then returns to the default interface.  At this point, though, clicking on the 'load model' menu doesn't work anymore. 

    I also tried the .stl file from the other bug I created (id 2493028 "cutter path seems to intersect mesh")  I can open the .stl file in pycam without problem.  However, if I open the .blend file and reexport the stl, the new stl file doesn't work in pycam.

     
  • Lode Leroy

    Lode Leroy - 2010-03-15

    could you post the stl file that fails to load? or mail it to me at lode_leroy@hotmail.com

     
  • Odemia

    Odemia - 2010-03-17

    Having the same problem.  Sending the files via email (can't seem to attach files to bugs).

     
  • Lode Leroy

    Lode Leroy - 2010-03-17

    the stl file "cube.stl" exported by blender seems to have no surface normals,
    which causes the import to fail. a workaround was added in svn

     

Log in to post a comment.