Removing manifold faces

I’m working on a maze generator, and as of so far, it just places cubes everywhere they need to be. The problem is that they are created all as separate objects rather than as one coherent mesh, and there are non-manifold faces between every adjacent cube. I’m creating the cubes with primitive_cube_add() in my script.

I’m wondering if anyone has an easy way (hopefully via python but not necessary) to remove all the non-manifold faces, so that there is a clear path between all the cubes. Here is a small example of what I’m dealing with.

My second question is probably better off in the coding forum, but how do I create the cubes in edit-mode so they are all part of one mesh? This would speed up the code a lot and not make the viewport lag with thousands of cubes.


Select menu -> interior faces, X -> faces.

Thanks much!