Scripting: low level join meshes / elements (hopefully with bmesh)? Currently I only know of one way to join meshes - using the join operator:

bpy.ops.object.join()


This has an annoying overhead of additional operations required to select the objects you want to join, etc.

But what if I only want to join elements from two different meshes?
This will be even more cumbersome with traditional methods: select the object, go to edit mode, select the relevant elements, duplicate them, separate them to a new mesh, join the new mesh with the other mesh...

It would be much nicer if I could just create two bmesh objects, then directly copy elements from one to the other. Something like this currently illegal code:

for v in bm1.verts:
    bm2.verts.add( v )

# or:
bm2.edges.add( bm1.edges[5] )


At the moment this requires adding the vertices first via their coordinates, then adding faces or edges by referencing the relevant new verts.

# Example for adding all the edges from another bmesh object
current_last_vert_index = len( bm2.verts ) - 1
for v in bm1.verts:
    bm2.verts.new( v.co )

for e in bm1.edges:
    verts = [ bm2.verts[ current_last_vert_index + v.index ] for v in e.verts ]
    bm2.edges.new( verts )


So, any better way to do this?
The best solution I found so far is using the bmesh.from_mesh( mesh ) method.
Apparently, if you call this method more than once, it will add the 2nd mesh to the first, thus effectively joining them:

import bpy, bmesh

bm = bmesh.new()
bm.from_mesh( mesh1 ) # Add first mesh
bm.from_mesh( mesh2 ) # Add 2nd mesh


However, this does not really help with adding individual components from another mesh or bmesh in a direct manner.