Code Monkey home page Code Monkey logo

Comments (18)

wolph avatar wolph commented on August 25, 2024

It's most likely that you have a different stl module installed.

Try pip uninstall stl and pip uninstall numpy-stl. After that reinstall the module with pip install numpy-stl

from numpy-stl.

AlexLee avatar AlexLee commented on August 25, 2024

numpystl
@wolph Thanks for the reply. How come the Mesh class only has a placeholder pass? That might be why your_mesh = mesh.Mesh.from_file('some_file.stl') in the example is not working

To be sure, I uninstalled numpy-stl and reinstalled it again.

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

It's not just a placeholder, if you look careful you'll see that it inherits stl.BaseStl: https://github.com/WoLpH/numpy-stl/blob/master/stl/stl.py#L33

The Mesh name is a logical name for usage, the BaseStl contains the stl file reading and the actual mesh code is in BaseMesh: https://github.com/WoLpH/numpy-stl/blob/master/stl/base.py#L55

from numpy-stl.

AlexLee avatar AlexLee commented on August 25, 2024

@wolph Thanks for the follow up. So what would be the correct way of calling the from_file method?

As you suggested, I typed pip uninstall stl to make sure there wasn't an additional "stl" library installed (there wasn't) and then I typed pip uninstall numpy-stl. Then I reinstalled numpy-stl pip install numpy-stl

I am using the first example that you gave in "Quickstart". your_mesh = mesh.Mesh.from_file('some_file.stl') gives me an error message stating that "mesh is not defined"

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

The example in your original question is correct and should function without any problems:

import numpy
from stl import mesh
your_mesh = mesh.Mesh.from_file('some_file.stl')

If it doesn't than I would recommend checking what is imported when you run the code. A conflict with a different module seems likely:

import stl
print 'stl file', stl.__file__
from stl import mesh
print 'mesh file', mesh.__file__

from numpy-stl.

AlexLee avatar AlexLee commented on August 25, 2024

@wolph Thanks again. Does the STL need to be made manifold or repaired in meshlab/netfabb before importing? I think the issue is with the STL file that I am using. I get an error message

TypeError: 'NoneType' object is not iterable

I used one of your example stl files (star.stl) and it worked fine

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

It shouldn't need a specific format, any type of STL file should function. Would you be able to add to upload the STL file here?

from numpy-stl.

AlexLee avatar AlexLee commented on August 25, 2024

see attached. one has holes filled, the other does not.
Archive.zip

from numpy-stl.

AlexLee avatar AlexLee commented on August 25, 2024

@wolph were you able to load the stl files that I posted?

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

Sorry @AlexLee, haven't had the time yet. I'll look at it soon.

from numpy-stl.

Gjacquenot avatar Gjacquenot commented on August 25, 2024

I succeed in loading both files with MeshLab.
With numpy-stl, I could just open and load 'plane_quadric6.stl'

from stl import mesh
m=mesh.Mesh.from_file('plane_quadric6.stl')

The other file creates problem:

m=mesh.Mesh.from_file('plane_noholes.stl')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-47d6ca79bd4e> in <module>()
----> 1 m=mesh.Mesh.from_file('plane_noholes.stl')

C:\Python27\lib\site-packages\stl\stl.pyc in from_file(cls, filename, calculate_normals, fh, mode, **kwargs)
    272         else:
    273             with open(filename, 'rb') as fh:
--> 274                 name, data = cls.load(fh, mode=mode)
    275
    276         return cls(data, calculate_normals, name=name, **kwargs)

TypeError: 'NoneType' object is not iterable

from numpy-stl.

Gjacquenot avatar Gjacquenot commented on August 25, 2024

I figure out where is the problem. The header of the file plane_noholes.stl is an empty string of 80 characters.

In this case, the following instructions in file stl.py causes a premature return

    if not header.strip():
        return

I will try to propose a patch that does not break the tests...

@wolph : Maybe you can explain the reason of this test?

from numpy-stl.

Gjacquenot avatar Gjacquenot commented on August 25, 2024

@wolph : I have tried deleting these two lines, but I break the current tests (See PR #29)
@AlexLee : For the time being, you can load your STL file plane_noholes.stl by changing the header of this file: open the file with a text editor, replace the first space with any another character, save it and then you can load it with m=mesh.Mesh.from_file('plane_noholes.stl'). When this bug will be fixed, you won't have to do this nasty operation.

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

@Gjacquenot I suppose there is no real reason for that test. There is nothing in the (ill-defined) binary STL standard that requires a header to have content.

To fix the tests I believe an additional test should be added to the code. Instead of:

count, = struct.unpack(s('@i'), b(fh.read(COUNT_SIZE)))

Something along the lines of:

count_data = fh.read(COUNT_SIZE)
if len(count_data) != COUNT_SIZE:
    count = 0
else:
    count, = struct.unpack(s('@i'), b(count_data))

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

Also, thank you very much for helping out :)
It's greatly appreciated!

from numpy-stl.

Gjacquenot avatar Gjacquenot commented on August 25, 2024

@AlexLee : With PR #29 , your binary files can directly be loaded!

from numpy-stl.

Gjacquenot avatar Gjacquenot commented on August 25, 2024

@wolph, @AlexLee : I think it can now be closed

from numpy-stl.

wolph avatar wolph commented on August 25, 2024

The pull request has been merged so I think this issue has been resolved. If not, please let me know @AlexLee :)

from numpy-stl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.