I need to merge 2 vertices into one with bpy.ops.mesh.merge(type='LAST'). I select 2 vertices, however there is no saved select order to them so I can't use merge with parameter 'LAST'.
import bpy, bmesh
obj = bpy.context.scene.objects.active
objData = obj.data
bpy.ops.object.mode_set(mode='EDIT')
meshData = bmesh.from_edit_mesh(objData)
vertices = meshData.verts
#select 2 testing vertices
vertices[0].select = True
vertices[1].select = True
bpy.ops.mesh.merge(type='LAST')
I get this error:
TypeError: Converting py args to operator properties: enum "LAST" not found in ('CENTER', 'CURSOR', 'COLLAPSE')
Error: Python script fail, look in the console for now...
So instead I tried to snap the 3D cursor to the first selected vertex to be able to use merge with parameter 'CURSOR':
#select 2 testing vertices
vertices[0].select = True
bpy.ops.view3d.snap_cursor_to_selected()
vertices[1].select = True
bpy.ops.mesh.merge(type='CURSOR')
And I get this error:
RuntimeError: Operator bpy.ops.view3d.snap_cursor_to_selected.poll() failed, context is incorrect
Error: Python script fail, look in the console for now...
So my questions are:
How do I change context to View 3D (if only 'OBJECT', 'EDIT', 'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT' are available) or am I missing something? And how come I am able to manually do it on the object in EDIT mode?
Is there any way to edit the selection order of vertices so I can use merge with parameter 'LAST' as I originally intended?