Dust
Dust

Reputation: 13

Can not save mesh when using pymeshlab(MeshSet.save_current_mesh())

I tried the simplest sample of Pymeshlab but there is a Exception.

import pymeshlab


ms = pymeshlab.MeshSet()
ms.load_new_mesh('test.obj')
ms.generate_convex_hull()
ms.save_current_mesh('convex_hull.ply')
File "main.py", line 7, in <module>
    ms.save_current_mesh('convex_hull.ply')
pymeshlab.pmeshlab.PyMeshLabException

The Exception is strange. It contains nothing.

Screen shoot

My obj file is normal. My python version is 3.11.2

Can anyone tell me how to handle it?

Upvotes: 1

Views: 717

Answers (1)

Rockcat
Rockcat

Reputation: 3240

I can confirm that this test case is working in my computer, so you can try this to debug your program.

  1. I suggest to debug your code adding lines like thoses:
print(ms.current_mesh().vertex_number(),'vertex')
print(ms.current_mesh().face_number(), 'faces')

before and after the call to ms.generate_convex_hull(). This allows to check that the mesh has been correctly imported and built. Please, note that it is possible that your input mesh is somehow degenerated (for example, in your screenshot, every Z coordinate has the same value).

  1. Be sure that you have permissions to write files in the directory where you execute the script (same directory that contains the test.obj file). Try to write a small text file using pure python, (not meshlab)
with open("convex_hull.txt", "w") as f:
    print("Test file output", file=f)
    print(ms.current_mesh().vertex_number(),'vertex', file=f)
    print(ms.current_mesh().face_number(), 'faces', file=f)

Upvotes: 0

Related Questions