12/5/2025 PYTHON

We (me and ChatGPT) made this useful script that creates 2D geometry from a list of verts.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import bpy
import bmesh

all_objects = bpy.context.scene.objects
for obj in all_objects:
if “base” in obj.name.lower():
bpy.data.objects.remove(obj, do_unlink = True)

Create new mesh + object

mesh = bpy.data.meshes.new(“GeneratedMesh”)
obj = bpy.data.objects.new(“Base”, mesh)
bpy.context.collection.objects.link(obj)

Begin bmesh

bm = bmesh.new()

— Create verts —

coords = [
(0, 0, 0),
(4, 0, 0),
(4, 0, 2),
(1, 0, 2),
(1, 0, 10),
(0, 0, 10),
]

verts = [bm.verts.new(c) for c in coords]

Make sure bmesh indexes update

bm.verts.ensure_lookup_table()

— Create edges (connect verts in sequence) —

for i in range(len(verts) – 1):
bm.edges.new((verts[i], verts[i+1]))

Write to mesh

bm.to_mesh(mesh)
bm.free()