I would like to join two faces which are in the same mesh by using bmesh.utils.face_join(faces, remove=True)
, and the details from blender 2.78c API documentation show:
Firstly, I had a square plane whose vertices are((-1, -1, 0), (1, -1, 0), (1, 1, 0), (-1, 1, 0))
Secondly, I used the following codes to add a triangle plane whose vertices are ((0, 0, 0), (2, 2, 0), (2, -2, 0)) to the mesh containing the square plane.
And then joined the square plane and the triangle plane together.
import bpy
import bmesh
from mathutils import Vector
# Setting scene and camera
scene = bpy.context.scene
# All objects in Scene
objects_in_scene = scene.objects
# get the square plane
for obj in objects_in_scene:
if (hasattr(obj.data, "vertices")):
squareObj = obj
break
# vertices of the triangle plane
verts2 = [(0, 0, 0), (2, 2, 0), (2, -2, 0)]
# add vertices
squareObj.data.vertices.add(3)
squareObj.data.vertices[-3].co = verts2[0]
squareObj.data.vertices[-2].co = verts2[1]
squareObj.data.vertices[-1].co = verts2[2]
# change mode to editmode
bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(squareObj.data)
# add the triangle face
bm.verts.ensure_lookup_table()
set_of_verts = set(bm.verts[i] for i in range(4,7))
bm.faces.new(set_of_verts)
# update the bmesh
bmesh.update_edit_mesh(squareObj.data)
# join the two faces and print the new face
print(bmesh.utils.face_join(bm.faces, remove=True))
However, I got the error message bellow:
TypeError: face_join() takes no keyword arguments
I modified the codes in the end line and use print(bmesh.utils.face_join(bm.faces))
instead.
The script could run but I got feedback, "None", which meant failure according to blender API documentation.
In fact, I am trying to merge two faces into one face with python like this.
I found this operation in blender 2.78c API documentation and tried it.
Please tell me if you have any suggestion about why can't use bmesh.utils.face_join(faces)
and bmesh.utils.face_join(faces, remove=True)
, or how to merge two faces into one face with python.
Thank you in advanced.