How can I get the length of an edge with a script? I want to identify a face by its vertex group and get the lengths of its edges. I've gotten as far as identifying the vertex group so I can select it or get the indices - what next? Do I have to do some complicated math to get distances between points in 3d space or is there a direct way to get the edge length as it is displayed in the overlay? The angle would be great too, but I'm trying to take small bites.

  • 3
  • $\begingroup$ @batFINGER Oof. BMESH. Nothing confuses me like BMESH. It didn't work to select faces with vertex groups because it selected too many faces so I switched to selecting them with material slots. I figured that out, but now it sounds like I need to figure out how to do it with BMESH. I haven't wrapped my head around that process yet. Here goes... $\endgroup$ Commented Mar 10, 2020 at 1:34

1 Answer 1


That was easier than I expected!

import bpy
import bmesh
i = 0
for mat_slot in obj.material_slots:
    #enter edit mode
    #deselect all
    #choose the active slot based on the loop number
    bpy.context.object.active_material_index = i
    #select the faces of the active slot
    #make a bmesh from the mesh
    me = bpy.context.object.data
    bm = bmesh.from_edit_mesh(me)
    #list to populate with lengths
    edge_lengths = []
    #if edge is selected, get its length
    for e in bm.edges:
        if e.select:
  • 1
    $\begingroup$ python comes with enumerate() $\endgroup$
    – brockmann
    Commented Mar 10, 2020 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .