wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

Name attribute is not preserved when saved. #121

Closed bwoodsend closed 4 years ago

bwoodsend commented 4 years ago

Here's my code.

from stl.mesh import Mesh
path = "my_stl.stl"

# Load a mesh
mesh = Mesh.from_file(path)
# Rename it
mesh.name = b"alternative_name"
# Save 
mesh.save(path)
# then reopen it
print(Mesh.from_file(path).name)

I'd expect to get b'alternative_name' but instead I get the just get the numpy-stl header with the beginning of path (below).

b'numpy-stl (2.10.1) 2020-03-15 22:49:39.548156 e:\\uni\\comparison of 3d dental mod'

Looking at the source code I see that that header appears to be hard coded in mesh.save(). Is there a reason you chose to do it that way? Could it change?

wolph commented 4 years ago

The reason for that header is mostly because most other apps and libraries appear to do something similar. But a different kind of header is certainly an option. I can add it to the todo list but I'm really strapped for time at the moment so I won't create a new release within a few weeks or so.

bwoodsend commented 4 years ago

That's OK - I'm not in a hurry. Thanks.

wolph commented 4 years ago

I've created a new release where the header can be modified by either inheriting/subclassing Mesh to override the get_header method: https://github.com/WoLpH/numpy-stl/blob/137fa7776c2d18fab6fc5fc94cd1a14594f08fe1/stl/stl.py#L282-L289

Or you can monkeypatch either get_header for your mesh instance or monkeypatch stl.HEADER_FORMAT for a global change.

bwoodsend commented 4 years ago

That's perfect. Thanks a lot!