Comments (18)
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.
@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.
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.
@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.
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.
@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.
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.
see attached. one has holes filled, the other does not.
Archive.zip
from numpy-stl.
@wolph were you able to load the stl files that I posted?
from numpy-stl.
Sorry @AlexLee, haven't had the time yet. I'll look at it soon.
from numpy-stl.
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.
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.
@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.
@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.
Also, thank you very much for helping out :)
It's greatly appreciated!
from numpy-stl.
@AlexLee : With PR #29 , your binary files can directly be loaded!
from numpy-stl.
@wolph, @AlexLee : I think it can now be closed
from numpy-stl.
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)
- Combined STL HOT 1
- How to use `test` modules HOT 1
- Z-height HOT 5
- Graph Generation is Blank HOT 1
- Parsing ASCII STL ending with "end solid" raises exception HOT 2
- about projection area HOT 1
- shape cant find HOT 1
- Save multi-part stls HOT 3
- Possible error in volume calculations HOT 4
- Can we check if two different stl files are overlapping each other HOT 1
- saving ascii STL HOT 2
- Merge STL question HOT 4
- AttributeError: module 'stl' has no attribute 'BaseStl HOT 1
- Computing the Max Z-height for double rotation HOT 3
- More info needed on stl atributes HOT 3
- the centroids of a stl file was not update after i rotated the stl file HOT 3
- How can i find linear parameters of stl model? HOT 2
- can't make image array into *.stl HOT 2
- dependency to deprecated `setuptools.command.test` breaks installation HOT 2
- numpy 2.x breaks the tests: ValueError: could not convert string to float: b'np.float32(0.0)' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy-stl.