Create Mesh from Empties

Generate a connected mesh using the world-space positions of empties in a collection.
Broken button... I'll fix it eventually...
import bpy
import bmesh
from mathutils import Vector
# Set your collection name here
collection_name = "Empties"
# Get the collection
collection = bpy.data.collections.get(collection_name)
if not collection:
raise Exception(f"Collection '{collection_name}' not found.")
# Gather world positions of all empties in the collection
positions = [obj.matrix_world.translation for obj in collection.objects if obj.type == 'EMPTY']
if len(positions) < 2:
raise Exception("Need at least 2 empties to create a mesh.")
# Create new mesh and object
mesh = bpy.data.meshes.new("EmptyMesh")
obj = bpy.data.objects.new("EmptyMeshObj", mesh)
bpy.context.collection.objects.link(obj)
# Create geometry
bm = bmesh.new()
verts = [bm.verts.new(pos) for pos in positions]
bm.verts.ensure_lookup_table()
# Option 1: Create a connected line (polyline)
for i in range(len(verts) - 1):
bm.edges.new((verts[i], verts[i + 1]))
# Optional: Close the loop into a face (uncomment below)
# if len(verts) > 2:
# bm.faces.new(verts)
# Finish and write to mesh
bm.to_mesh(mesh)
bm.free()
Description
This Blender Python script creates a mesh object by sampling the positions of empties from a specified collection. It reads each empty’s world-space coordinates and creates vertices at those locations. The script then connects these vertices with edges to form a polyline. Optionally, you can close the loop to generate a face, allowing fast mesh generation from control points or rig markers in 3D space. This tool is ideal for creating guides, light paths, rig helpers, or surface outlines from reference points.
