I am trying to write a python script that will convert triangular-mesh objects to quad-mesh objects.
For example, image (a) will be my input (.obj/.stl
) file and image (b) will be the output.
I am a noob with mesh-algorithms or how they work all together. So, far this is the script I have written:
import bpy
inp = 'mushroom-shelve-1-merged.obj'
# Load the triangle mesh OBJ file
bpy.ops.import_scene.obj(filepath=inp,
use_smooth_groups=False,
use_image_search=False)
# Get the imported mesh
obj = bpy.context.selected_objects[0]
# Convert triangles to quads
# The `beauty` parameter can be set to False if desired
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.tris_convert_to_quads(beauty=True)
bpy.ops.object.mode_set(mode='OBJECT')
# Export to OBJ with quads
bpy.ops.export_scene.obj(filepath='quad_mesh.obj')
This results in the following error:
Traceback (most recent call last):
File "/home/arrafi/mesh-convert-application/test.py", line 8, in <module>
bpy.ops.import_scene.obj(filepath=inp,
File "/home/arrafi/mesh-convert-application/venv/lib/python3.10/site-packages/bpy/4.0/scripts/modules/bpy/ops.py", line 109, in __call__
ret = _op_call(self.idname_py(), kw)
AttributeError: Calling operator "bpy.ops.import_scene.obj" error, could not be found
Any help with what I am doing wrong here would be greatly appreciated.
- Also please provide your suggestions for if you know any better way to convert triangular-mesh to quad-mesh with Python.
- If you guys know of any API that I can call with python to do the conversion, that would work too.