Dessia-tech / volmdlr

A python VOLume MoDeLeR computations-oriented with STEP support for import/export
GNU Lesser General Public License v2.1
27 stars 9 forks source link

Error: Mesh3D.to_stl #1294

Closed MackJoly closed 3 months ago

MackJoly commented 4 months ago

Hi, I have an error during the export of a Mesh3D to stl:

File "C:\Users\Mack\AppData\Local\Temp\ipykernel_19816\3074752019.py", line 1, in <module>
    mesh.to_stl('CPOM0WGM0U_binary.stl')

  File "c:\users\mack\documents\git\dessia_common\dessia_common\core.py", line 711, in to_stl
    with open(filepath, 'wb', encoding='utf-8') as file:

ValueError: binary mode doesn't take an encoding argument

No problem with to_stl_stream

from volmdlr.display import Mesh3D
mesh = Mesh3D.from_stl_file('file.stl')
mesh.to_stl('filebinary.stl')
pgibertini commented 4 months ago

Hello @MackJoly, Indeed, the to_stl / to_stl_stream methods of the PhysicalObject class are not overloaded in the Mesh3D object.

Instead, I created methods save_to_stl_file, save_to_stl_stream (and for other formats).

But it is confusing, and we should make the usage clearer.

MackJoly commented 4 months ago

Hello @pgibertini , Thanks for the answer ! Indeed I didn't pay enough attention to the methods it's my fault, I am sorry for the bothering !

pgibertini commented 4 months ago

I just tested and I am facing another error on master:

Traceback (most recent call last):
  File "/home/gibertini/PycharmProjects/Dessia/venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-b76d18794df3>", line 1, in <module>
    mesh5.to_stl("a")
  File "/home/gibertini/PycharmProjects/Dessia/venv/lib/python3.10/site-packages/dessia_common/core.py", line 682, in to_stl
    return self.volmdlr_volume_model().to_stl(filepath=filepath)
  File "/home/gibertini/PycharmProjects/Dessia/volmdlr/volmdlr/core.py", line 1572, in to_stl
    self.to_mesh3d().save_to_stl_file(filepath)
  File "/home/gibertini/PycharmProjects/Dessia/volmdlr/volmdlr/core.py", line 1551, in to_mesh3d
    mesh = self.primitives[0].triangulation()
AttributeError: 'Mesh3D' object has no attribute 'triangulation'

This error is fixed on future volmdlr 0.17.0, so to_stl feature will work on volmdlr 0.17.0

I think you are using an old version of dessia_common? I have 0.15.3 and not this problem

MackJoly commented 4 months ago

I am on 0.16 of dessia_common but I think that dessia_common and volmdlr and not connected anymore

pgibertini commented 4 months ago

Hello @pgibertini , Thanks for the answer ! Indeed I didn't pay enough attention to the methods it's my fault, I am sorry for the bothering !

no problem

pgibertini commented 4 months ago

I am on 0.16 of dessia_common but I think that dessia_common and volmdlr and not connected anymore

As volmdlr objects inherit from dessia_common.PhysicalObject, and to_stl methods are defined in PhysicalObject class, it is a dessia_common issue introduced in dessia_common 0.16