I've got traingluated mesh in which I want to select longest edge of each triangle. I have a feeling that this isn't hard via python script, but my coding skills are.... well not good. I know that you have to iterate through triangles in an object, then compare edge lenght, add longest one to some group and at the end select this group - I just don't know how to code it :( This is a workaround to not very good tris-to-quad tool.


1 Answer 1


Bmesh script

Simply running through and selecting the longest edge of each tri, the result can have any of 1, 2 or all edges of tri selected.

Added code try and avoid this somewhat.

Test script showing how to:

  • Load current edit mesh into bmesh
  • Find all triangles in bmesh
  • Find the longest edge and select it.
  • Update the edit mesh.


import bpy
import bmesh

context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

# triangles
tris = [f for f in bm.faces if len(f.edges) == 3]
# deselect all edges
for e in bm.edges:
    e.select = False

for f in tris:
    # if an edge already selected continue
    if any(t.select for t in f.edges):
    # sort by length and selected (if not using continue)
    edges = sorted(f.edges, key=lambda t : [t.calc_length(), t.select])
    # pop the last and select
    edges.pop().select = True



Each edge has a link_faces collection. If there are two link faces (not boundary) and the edge is longest of all edges in both faces, then turn into quad.

  • Find all edges that have two triangle link faces
  • For each these edges, (sorted maybe): if it is longest edge of 2 faces and no other edges selected disolve edge to make this face a quad.
  • otherwise go to next edge.

You must log in to answer this question.

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