0
$\begingroup$

I have a mesh circle with 32 vertices and I am trying to get the edge loop of the circle (which is actually all vertices in sequence) with following code:

import bmesh
bm = bmesh.new()
bm.from_mesh(bpy.context.object.data)

bm.verts.ensure_lookup_table()
v_loops = bm.verts[0].link_loops
print(len(v_loops))

bm.edges.ensure_lookup_table()
e_loops = bm.edges[0].link_loops
print(len(e_loops))

However, at both places I get zero length of the edge loops. Am I doing anything wrong?

$\endgroup$
2
  • $\begingroup$ I think link_loops function checks which face loops use the vertex/edge. From documentation . For vertex: Loops that use this vertex (read-only). and for edge: Loops connected to this edge, (read-only). If you fill in a face with F then you get a value of 1. So it confirms my theory :) $\endgroup$ Aug 26 at 10:47
  • $\begingroup$ @HarryMcKenzie Yes, that's right :) So how to get the edge loops connected to selected vert or edge of a non-manifold mesh. I checked the relevant threads on stackexchange and they seem to be talking about manifold meshes only. $\endgroup$ Aug 27 at 11:38

1 Answer 1

0
$\begingroup$

This will take an input list of edges of any length, take the first element of the list as the starting edge and "walk" around the edge loop of a non-manifold loop until it finds the first edge it started with and return a list of edges of the loop. The key is the 3s.

3 is the number of edges each vert is connected to. If it was 4 then it would be looking for manifold edges.

def get_loop(edges):

    edge_loop = []
    edge = edges[0] # edge at the start of the edge loop

    # get BMLoop that points to the right direction
    for loop in edge.link_loops:
        if len(loop.vert.link_edges) == 3:
            break

    first_edge = edge
    edge_loop.append(first_edge)
    next_edge = 0

    # stop when reach the end of the edge loop
    while len(loop.vert.link_edges) == 3 and next_edge != first_edge:

        # jump between BMLoops to the next BMLoop we need
        loop = loop.link_loop_prev.link_loop_radial_prev.link_loop_prev

        # following edge in the edge loop
        next_edge = loop.edge
        if next_edge != first_edge:
            edge_loop.append(next_edge)

    return edge_loop
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.